clang++ and g++ difference. Who is right ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

clang++ and g++ difference. Who is right ?

Jean-Daniel Dupas-2
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.


-- Jean-Daniel




-- Jean-Daniel





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang++ and g++ difference. Who is right ?

Eli Friedman
On Wed, Jul 7, 2010 at 12:52 AM, Jean-Daniel Dupas
<[hidden email]> 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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev