Re: [cxx-abi-dev] Possibly ambiguous mangling of extern "C" functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cxx-abi-dev] Possibly ambiguous mangling of extern "C" functions




On Aug 20, 2008, at 4:19 AM, Mark Mitchell wrote:

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.

There is a well-formed varient of this case though:

extern "C" {
bool IsEmpty(char *); // (un)mangled as IsEmpty
typedef bool (&ref_func)(char *);
}
template<ref_func> struct CB { static int x; };
int *p = &CB<IsEmpty>::x;

John Spicer
Edison Design Group