[cxx-abi-dev] Possibly ambiguous mangling of extern "C" functions
Mark Mitchell
mark at codesourcery.com
Wed Aug 20 08:19:02 UTC 2008
David Vandevoorde wrote:
>> extern "C" bool IsEmpty(char *); // (un)mangled as IsEmpty
>> template<bool (&)(char *)> struct CB { static int x; };
>> // CB<IsEmpty> is mangled as "2CBIL_Z7IsEmptyEE"
>> int *p = &CB<IsEmpty>::x;
> Normally, we issue the following error on that example:
>
> "t.c", line 4: error: a reference of type "bool (&)(char *)" (not
> const-qualified) cannot be initialized with a value of type
> "bool (char *) C"
Yes, that's the right error. G++ has never implemented extern "C"
function *types*, so doesn't issue this kind of error. There are extern
"C" functions, but the linkage isn't part of the type per se. This is a
known bug.
So, now we're talking about mangling for an invalid C++ program, which
is outside the scope of the ABI.
> When I enable the emulation of GCC, we accept it and mangle it as
> _ZN2CBIXL_Z7IsEmptyEEE1xE.
>
> We also have a mode to emulate what we consider "GNU ABI bugs". When I
> enable that, we generate _ZN2CBIXL7IsEmptyEEE1xE.
The GCC output is actually:
_ZN2CBILZ7IsEmptyEE1xE
Indeed, GCC does not generate the "X...E" form here. Instead, it uses
the expr-primary production directly from the template-arg rule, which
makes sense since there is no complex expression here. However, I do
think that G++ is in error not to omit the underscore before the Z.
--
Mark Mitchell
CodeSourcery
mark at codesourcery.com
(650) 331-3385 x713
More information about the cxx-abi-dev
mailing list