@@ -5584,34 +5584,59 @@ <h4><a href="#closure-types">5.1.8 Closure Types (Lambdas)</a></h4>
55845584< h4 > < a href ="#lexical-ordering "> 5.1.9 Lexical ordering</ a > </ h4 >
55855585
55865586< p >
5587- Lexical ordering is used for numbering local entities
5588- (unnamed classes and enumerations,
5589- closure types, and static local variables)
5590- when there is no other way of distinguishing them.
5591- Except as described below, all local entities are to be numbered,
5592- even if subsequent optimization makes some of them unnecessary,
5593- or no mangled name is actually required for some of them.
5594- The ordering of entities appearing in a
5595- mem-initializer-list shall be the order that the entities appear in
5596- the source, which may be different from the order in which the
5597- initializers will be executed when the program runs.
5598- It is expected that this will be the 'natural' order in most compilers.
5599-
5600- < p >
5601- Within a non-template, the numbering
5602- is in strictly lexical order based on the original token sequence.
5603- Within a template instantiation, the numbering
5604- is established after packs are expanded and discarded statements in
5605- constexpr ifs are removed.
5587+ Lexical ordering is used for numbering local entities (named and unnamed
5588+ local classes and enumerations, closure types, and static local variables)
5589+ when there is no other way of distinguishing them. Except as described below,
5590+ all local entities are to be numbered, even if subsequent optimization makes
5591+ some of them unnecessary, or no mangled name is actually required for
5592+ some of them.
5593+
5594+ < p >
5595+ The order of entities is the source order of a key token unique to the
5596+ entity as if:
5597+
5598+ < ul >
5599+ < li > the discarded sub-statements of < tt > if constexpr</ tt > within a
5600+ template did not exist and
5601+ < li > pack expansions were lexically expanded.
5602+ </ ul >
5603+
5604+ < p > In all cases, this is meant to imitate the numbering that would
5605+ be produced by a simple implementation which numbered entities as it
5606+ processed the source and recursively expanded packs. Since discarded
5607+ substatements of < tt > if constexpr</ tt > are still processed in
5608+ non-template code, entities within them are still numbered.
5609+
5610+ < p > Entities may be lexically nested without being in different
5611+ contexts for the purposes of mangling. For example, the lambdas in
5612+ < code > [x = []{}]{}</ code > are both part of the enclosing context.
5613+ The order of such entities is determined by the source order of a key
5614+ token in the entity. In general, this token is the first token
5615+ past which the signature of the entity (as is necessary to mangle it)
5616+ is known:
5617+
5618+ < ul >
5619+ < li > The key token of a class or enum is the end of the
5620+ < code > enum-head-name</ code > (< code > enum-key</ code > if unnamed) or
5621+ < code > class-head-name</ code > (< code > class-key</ code > if unnamed)
5622+ in its first declaration.
5623+ < li > The key token of a lambda is its closing brace (< code > }</ code > ).
5624+ < li > The key token of a static local variable is the last token of its
5625+ < code > declarator</ code > (not its initializer).
5626+ </ ul >
5627+
5628+ < p >
56065629All entities from one expansion of a pack are considered to occur
56075630lexically before any entities from the next expansion of the same pack,
56085631but the ordering is otherwise based on the original token sequence.
56095632This is expected to match the numbering that would be established for
56105633the corresponding non-template generated by substitution into the template.
56115634As a consequence of these rules, the entity instantiated for a particular
56125635source construct can have a different mangling number in different
5613- instantiations of the same template.
5614- For example:
5636+ instantiations of the same template. An entity appearing in the original
5637+ source may also go entirely un-numbered if it appears in a discarded
5638+ sub-statement of < code > if constexpr</ code > or in a pack expansion of an
5639+ empty pack. For example:
56155640
56165641< code > < pre >
56175642void g(...);
@@ -5637,6 +5662,12 @@ <h4><a href="#lexical-ordering">5.1.9 Lexical ordering</a></h4>
56375662}
56385663</ pre > </ code >
56395664
5665+ < p >
5666+ Note that the numbering of entities appearing within a
5667+ < code > mem-initializer-list</ code > reflects the order that the
5668+ initializers appear in the source, which may be different from the
5669+ order in which the initializers will be executed when the program runs.
5670+
56405671< p >
56415672< a name ="mangling-compression ">
56425673< h4 > < a href ="#mangling-compression "> 5.1.10 Compression</ a > </ h4 >
0 commit comments