[cxx-abi-dev] Mangling of anonymous unions
Richard Smith
richardsmith at google.com
Mon Dec 9 22:52:10 UTC 2013
On Mon, Dec 9, 2013 at 1:48 PM, Richard Smith <richardsmith at google.com>wrote:
> On Mon, Dec 9, 2013 at 1:46 PM, Richard Smith <richardsmith at google.com>wrote:
>
>> Hi!
>>
>> 5.1.2 says: "For the purposes of mangling, the name of an anonymous union
>> is considered to be the name of the first named data member found by a
>> pre-order, depth-first, declaration-order walk of the data members of the
>> anonymous union."
>>
>
Experimentation shows that Clang, GCC, and EDG interpret this as applying
to the implicit object of anonymous union type, not to the anonymous union
(type) itself. If that's the intent, we should probably update the document
to say that.
> 5.1.6 says: "In case of unnamed local types (excluding unnamed types that
>> have acquired a "name for linkage purposes"), the "name" the unqualified
>> name is encoded as an <unnamed-type-name>"
>>
>
> Sorry, I meant to quote this section of 5.1.5 here:
>
> "Unnamed class, union, and enum types that aren't closure types, that
> haven't acquired a "name for linkage purposes" (through a typedef), *and
> that aren't anonymous union types*, follow the same rule when they are
> defined in class scopes, with the underlying <unqualified-name> an
> <unnamed-type-name> of the form
>
> <unnamed-type-name> ::= Ut [ <nonnegative number> ] _"
>
>
>> Thus, given:
>>
>> struct A { union { int n; }; struct {} x; };
>> template<int A::*> struct X {};
>> void f(X<&A::n>, decltype(A::x)) {}
>>
>> ... the mangling of 'f' is _Z1f1XIXadL_ZN1A1n1nEEEENS0_Ut_E
>>
>> However, I can't find any implementation that actually follows these
>> rules.
>>
>> Clang and GCC give the anonymous union an unnamed type mangling instead
>> of an anonymous union mangling, and give _Z1f1XIXadL_ZN1AUt_1nEEEENS0_Ut0_E
>>
>> EDG follows the 5.1.6 rule but doesn't seem to implement the 5.1.2 rule,
>> and instead gives _Z1f1XIXadL_ZN1A4__C11nEEEENS0_Ut_E
>>
>>
>> What's the purpose of the special case in 5.1.2 and 5.1.6? The rules
>> would be simpler and more uniform if we adopted the Clang and GCC behavior,
>> and we don't seem to lose much by doing so. Thoughts?
>>
>
It seems that the current behavior is:
Clang and GCC include anonymous unions in the unnamed type counting and
mangling, ignoring the relevant part of 5.1.5. This happens both within
classes (as demonstrated above) and within functions:
template<typename T> int f(T *);
void g() { union { int n = f(this); }; }
EDG (and ICC) excludes anonymous unions from the unnamed type counting and
mangling (per 5.1.5), and instead uses some internal name (__C1, ...) for
the type.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20131209/53162a40/attachment.html>
More information about the cxx-abi-dev
mailing list