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