@@ -4533,13 +4533,13 @@ <h5><a href="#mangling.dependent">Dependent constructs in templates</a></h5>
45334533< h5 > < a href ="#mangling.anonymous "> Anonymous entities</ a > </ h5 >
45344534
45354535< p >
4536- For the purposes of mangling, the name of an anonymous union is
4537- considered to be the name of the first named data member found by a
4536+ For the purposes of mangling, the name of an anonymous struct or union
4537+ is considered to be the name of the first named data member found by a
45384538pre-order, depth-first, declaration-order walk of the data members of
4539- the anonymous union . If there is no such data member (i.e., if all of
4540- the data members in the union are unnamed), then there is no way for a
4541- program to refer to the anonymous union , and there is therefore no
4542- need to mangle its name.
4539+ the anonymous type . If there is no such data member (i.e., if all of
4540+ the data members in the struct or union are unnamed), then there is
4541+ no way for a program to refer to the anonymous type , and there is
4542+ therefore no need to mangle its name.
45434543</ p >
45444544
45454545< p >
@@ -5529,13 +5529,188 @@ <h5><a href="#mangle.template-arg">5.1.5.10 Template Arguments</a></h5>
55295529</ code > </ font > </ pre >
55305530
55315531< p >
5532- Type arguments appear using their regular encoding.
5533- For example, the template class "A<char, float>" is encoded as "1AIcfE".
5534- A slightly more involved example is
5535- a dependent function parameter type "A<T2>::X"
5536- (T2 is the second template parameter)
5537- which is encoded as "N1AIT0_E1XE",
5538- where the "N...E" construct is used to describe a qualified name.
5532+ Template arguments can be dependent when a template argument list
5533+ is written in a context where dependent structures must be mangled.
5534+ For example, if the parameter type of a function template is
5535+ < code > A<T2>::X</ code > , where < code > T2</ code > is the second
5536+ template parameter of the function template, this is mangled as
5537+ < code class =mangle > N1AIT0_E1XE</ code > .
5538+
5539+ < p >
5540+ Template type arguments and template template arguments are mangled
5541+ using their regular encoding. For example, the class template
5542+ specialization < code > A<char, float></ code > is encoded as
5543+ < code class =mangle > 1AIcfE</ code > .
5544+
5545+ < p >
5546+ A non-type template argument is considered dependent if either the
5547+ argument expression is instantiation-dependent or it is not matched
5548+ with a template parameter of non-dependent type. (The latter can
5549+ happen if, for example, the template name is dependent and not a
5550+ template parameter.) If so, it is mangled as an expression in the
5551+ usual way for a < a href ="#mangling.dependent "> dependent mangling</ a > .
5552+ Otherwise, it is converted to the template parameter type,
5553+ constant-evaluated, and then mangled as a value. For example:
5554+
5555+ < code > < pre >
5556+ template < class T, T value > class A;
5557+
5558+ template <class U, template <class T, T N> class Temp> void f(Temp<U, 4+5>) {}
5559+
5560+ f< unsigned , A > // _Z1fIj1AEvT0_IT_XplLi4ELi5EEE
5561+ // The template parameter type is dependent, and so the template
5562+ // argument is mangled as a dependent expression without any
5563+ // constant-folding.
5564+
5565+ template <template <class T, T N> class Temp> void g(Temp<unsigned, 4+5>) {}
5566+ g< A > // _Z1gI1AEvT_IjLj9EE
5567+ // The template parameter type is not dependent, and so the template
5568+ // argument is converted to unsigned and constant-evaluated.
5569+ </ pre > </ code >
5570+
5571+ < p >
5572+ Non-type template argument values of integer, enumerated,
5573+ floating-point, or complex type are mangled as
5574+ < a href ="#mangling.literal "> literals</ a > of the template parameter
5575+ type. Note that this can produce combinations which cannot normally
5576+ be written in the source language, such as a literal of
5577+ < code > short</ code > type.
5578+
5579+ < p >
5580+ Non-type template argument values of pointer or member pointer type
5581+ that are null are mangled as as a literal < code > 0</ code > of the
5582+ template parameter type. For example:
5583+
5584+ < code > < pre >
5585+ struct A;
5586+ template <void (A::*)()> void f();
5587+
5588+ f<nullptr> // _Z1fILM1AFvvE0EEvv
5589+ </ pre > </ code >
5590+
5591+ < p >
5592+ Non-type template argument values of reference or pointer type
5593+ are mangled using the < a href ="#mangling.subobject-specifier "> subobject
5594+ specifier expression</ a > for the argument. If this is a simple
5595+ declaration reference, it may be mangled as an
5596+ < code > << a href ="#mangle.expr-primary "> expr-primary</ a > ></ code > .
5597+
5598+ < p >
5599+ Non-type template argument values of member pointer type
5600+ that are not null are mangled as expressions applying the
5601+ operator < code > &</ code > to the member function declaration
5602+ as if it were a regular function. (Note that this does not
5603+ distinguish between member pointers that have been converted
5604+ to different types.) For example:
5605+
5606+ < code > < pre >
5607+ struct A {
5608+ void foo();
5609+ };
5610+ template <void (A::*)()> void f();
5611+
5612+ f<&A::foo> // _Z1fIXadL_ZN1A3fooEvEEEvv
5613+ </ pre > </ code >
5614+
5615+ < p >
5616+ Non-type template argument values of class type are mangled as
5617+ a direct initialization (< code > tl</ code > ) of the class type
5618+ using the < a href ="#mangling.member-initializer-sequence "> member
5619+ initiializer sequence</ a > for the argument.
5620+
5621+ < a name ="mangling.subobject-specifier ">
5622+ < h5 > < a href ="#mangling.subobject-specifier "> 5.1.5.11 Subobject specifier expressions</ a > </ h5 >
5623+ </ a >
5624+
5625+ < p >
5626+ Constant evaluation may result in a pointer or reference to a specific
5627+ subobject of an object of static storage duration. This subobject is
5628+ identified in the mangling as if written with a specific expression,
5629+ called its subobject specifier expression.
5630+
5631+ < p >
5632+ (To be specified. See
5633+ < a href ="https://github.com/itanium-cxx-abi/cxx-abi/issues/47 "> for now</ a > .)
5634+
5635+ < a name ="mangling.member-initializer-sequence ">
5636+ < h5 > < a href ="#mangling.member-initializer-sequence "> 5.1.5.12 Member initializer sequences</ a > </ h5 >
5637+ </ a >
5638+
5639+ < p >
5640+ The constant evaluation of an expression of class type assigns
5641+ a constant value to each non-static data member of the class or,
5642+ if the class is a union, to at most one non-static data member,
5643+ called the active union member. Under the standard, this exact
5644+ structure uniquely determines a value, including whether a union
5645+ has an active union member member and (if so) which one. As
5646+ different values can produce different template specializations,
5647+ this structure must be faithfully represented in the mangling of
5648+ a value as a template argument.
5649+
5650+ < p >
5651+ A value is converted to a flattened sequence of values by applying
5652+ the following expansions until no values of array or non-union class
5653+ type remain:
5654+ < ul compact >
5655+ < li > A value of array type is replaced by its element values in
5656+ index order.
5657+ < li > A value of non-union class type is replaced by the values
5658+ of its base subobjects, in order of declaration, followed
5659+ by the values of its non-static data members, in order of
5660+ declaration.
5661+ </ ul >
5662+ Values satisfying the following conditions are then removed from
5663+ the end of the sequence until the final value does not satisfy
5664+ these conditions or the sequence is empty:
5665+ < ul compact >
5666+ < li > The value is of union type, it has an active union member,
5667+ that member is the first member of the union, and the
5668+ expansion of the value of that member according to these rules
5669+ is an empty sequence.
5670+ < li > The value is not of union type and is the zero value
5671+ of its type. (Note that because non-union values have all
5672+ been expanded, the value must not be of class type or contain
5673+ a value of class type.)
5674+ </ ul >
5675+
5676+ < p >
5677+ This sequence is then mangled as a sequence of
5678+ < code > << a href ="#mangle.braced-expression "> braced-expression</ a > ></ code > s
5679+ as follows:
5680+ < ul compact >
5681+ < li > If an element is a union that does not have an active member,
5682+ it is mangled as < code class =mangle > L <type > E</ code > .
5683+ < li > If an element is a union that has an active member, it is
5684+ mangled using the name of the active member as a designator
5685+ for the value of the active member. Note that if the active
5686+ member is an anonymous struct or union, its name for the purposes
5687+ of mangling is determined using the
5688+ < a href ="#mangling.anonymous "> usual rules</ a > .)
5689+ < li > Otherwise the value of the element is mangled in the usual way.
5690+ </ ul >
5691+
5692+ < p >
5693+ Note that qualifiers on the type of a non-static data member are not
5694+ part of the type of the value stored in that member.
5695+
5696+ < p >
5697+ For example:
5698+
5699+ < code > < pre >
5700+ struct A {
5701+ int x, y;
5702+ };
5703+ struct B {
5704+ union { A a; };
5705+ constexpr B(int x, int y) { a.x = x; a.y = y; }
5706+ };
5707+
5708+ template <B v> struct C {};
5709+
5710+ C<0,0> // 1CIXtl1BEEE
5711+ C<1,0> // 1CIXtl1BtlNS0_Ut_Edi1atl1ALi1EEEEEE
5712+ C<1,1> // 1CIXtl1BtlNS0_Ut_Edi1atl1ALi1ELi1EEEEEE
5713+ </ pre > </ code >
55395714
55405715< a name ="expressions ">
55415716< h4 > < a href ="#expressions "> 5.1.6 Expressions</ a > </ h4 >
0 commit comments