[cfe-dev] clang++ and g++ difference. Who is right ?
Eli Friedman
eli.friedman at gmail.com
Wed Jul 7 01:21:13 PDT 2010
On Wed, Jul 7, 2010 at 12:52 AM, Jean-Daniel Dupas
<devlists at shadowlab.org> wrote:
> Sorry for the previous incomplete post,
>
> I know there is come C++ expert around, so maybe someone may tell me who is right and who is wrong compiling the following code:
>
>
> ---------------- extern.cpp ---------------
> #include <stdio.h>
>
> namespace lldb_private { const char *GetVersion(); }
>
> const char * lldb_private::GetVersion() {
> extern const double LLDBVersionNumber;
> static char g_version_string[32];
> if (g_version_string[0] == '\0')
> ::snprintf (g_version_string, sizeof(g_version_string), "LLDB-%g", LLDBVersionNumber);
>
> return g_version_string;
> }
> -------------------------------------------
>
> clang++ mangle the external reference to LLDBVersionNumber using c++ rules => __ZN12lldb_private17LLDBVersionNumberE
> but g++ uses C rules => _LLDBVersionNumber
>
> As a side note, if you move the GetVersion() implementation inside the namespace body, both compilers use C++ mangling.
IIRC clang is correct; see [namespace.def]p6.
-Eli
More information about the cfe-dev
mailing list