Sun Studio 11: problem with
Hello,
Please cosider the code:
=======
Foo.h
=======
class Foo {
void bar(int param);
};
=======
Foo.cpp
=======
#include "Foo.h"
void Foo::bar(const int param) { // ***
}
Please look at the line marked with ***.
Please note "const" modifier of "param" (e.g. to disallow parameter
modification inside the function body).
Sun Studio 11 compiler compiles this without warnings or errors, but for other code that includes Foo.h and calls Foo::bar() it will generate different signature than the one generated compiling Foo.cpp: without and with "const" in mangled name correspondingly.
Obviously, this results in errors on link stage.
This seems a compiler bug for me.
If functions are same, there must be same signatures generated. If functions are not same, than the compiler, compiling Foo.cpp, should fail with error such as "bar() is not a member of class Foo".
The most correct solution that I see (and how other compilers work) is
not including "const" into signature of parameters passed by value, because such "const" doesn't affect the function caller in any way, but only is a precaution for possibly non desired modifications of parameter inside function body.
Best regards,
Anton

