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

[1343 byte] By [AntonKatilin] at [2007-11-26 9:34:35]
# 1

You have run into a documented bug in the "name mangling" used by Sun C++. If we fix this bug, we break a lot of programs that currently work. If we don't fix the bug, some valid programs (like yours) don't link.

You can find a discussion with code examples and workarounds in the C++ README file:

http://developers.sun.com/prodtech/cc/documentation/ss11/mr/READMEs/c++.html#cN ameMangling

clamage45 at 2007-7-7 0:23:59 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
Thank you very much for the info.
AntonKatilin at 2007-7-7 0:23:59 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

I see the compatibility point, but why the compiler doesn't prints warnings? The real problem is that correct code compiles without even warning and doesn't work at all. For example, we spent several hours to found where the problem is. Is there a key which forces the compiler to print warnings in such situations?

Best regards,

Vladimir Kondratyev

YourKit, LLC

http://www.yourkit.com

"Don't get lost in data, get information!"

vladimirkondratyev at 2007-7-7 0:23:59 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
The compiler does not currently have a way to warn about incorrect name mangling. Please submit a request for enhancement at bugs.sun.com
clamage45 at 2007-7-7 0:23:59 > top of Java-index,Development Tools,Solaris and Linux Development Tools...