[cxx-abi-dev] Mangling of anonymous unions

Richard Smith richardsmith at google.com
Mon Dec 9 21:48:33 UTC 2013


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."
>
> 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?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20131209/f180a1e9/attachment.html>


More information about the cxx-abi-dev mailing list