From Jason Turner

[expr.prim]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpdsorgp23/{from.md → to.md} +629 -209
tmp/tmpdsorgp23/{from.md → to.md} RENAMED
@@ -1,16 +1,19 @@
1
  ## Primary expressions <a id="expr.prim">[[expr.prim]]</a>
2
 
 
 
3
  ``` bnf
4
  primary-expression:
5
  literal
6
  this
7
  '(' expression ')'
8
  id-expression
9
  lambda-expression
10
  fold-expression
11
  requires-expression
 
12
  ```
13
 
14
  ### Literals <a id="expr.prim.literal">[[expr.prim.literal]]</a>
15
 
16
  The type of a *literal* is determined based on its form as specified in
@@ -30,19 +33,26 @@ The *current class* at a program point is the class associated with the
30
  innermost class scope containing that point.
31
 
32
  [*Note 1*: A *lambda-expression* does not introduce a class
33
  scope. — *end note*]
34
 
 
 
 
 
 
 
 
35
  If a declaration declares a member function or member function template
36
  of a class `X`, the expression `this` is a prvalue of type “pointer to
37
  *cv-qualifier-seq* `X`” wherever `X` is the current class between the
38
  optional *cv-qualifier-seq* and the end of the *function-definition*,
39
  *member-declarator*, or *declarator*. It shall not appear within the
40
- declaration of either a static member function or an explicit object
41
- member function of the current class (although its type and value
42
- category are defined within such member functions as they are within an
43
- implicit object member function).
44
 
45
  [*Note 2*: This is because declaration matching does not occur until
46
  the complete declarator is known. — *end note*]
47
 
48
  [*Note 3*:
@@ -106,62 +116,104 @@ otherwise indicated.
106
 
107
  ``` bnf
108
  id-expression:
109
  unqualified-id
110
  qualified-id
 
111
  ```
112
 
113
  An *id-expression* is a restricted form of a *primary-expression*.
114
 
115
  [*Note 1*: An *id-expression* can appear after `.` and `->` operators
116
  [[expr.ref]]. — *end note*]
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  If an *id-expression* E denotes a member M of an anonymous union
119
  [[class.union.anon]] U:
120
 
121
  - If U is a non-static data member, E refers to M as a member of the
122
- lookup context of the terminal name of E (after any transformation to
123
- a class member access expression [[class.mfct.non.static]]).
124
- \[*Example 1*: `o.x` is interpreted as `o.u.x`, where u names the
125
  anonymous union member. — *end example*]
126
  - Otherwise, E is interpreted as a class member access [[expr.ref]] that
127
  designates the member subobject M of the anonymous union variable for
128
- U. \[*Note 2*: Under this interpretation, E no longer denotes a
129
- non-static data member. — *end note*] \[*Example 2*: `N::x` is
130
  interpreted as `N::u.x`, where u names the anonymous union
131
  variable. — *end example*]
132
 
133
- An *id-expression* that denotes a non-static data member or implicit
134
- object member function of a class can only be used:
 
135
 
136
- - as part of a class member access [[expr.ref]] in which the object
137
- expression refers to the member’s class[^10] or a class derived from
138
- that class, or
139
  - to form a pointer to member [[expr.unary.op]], or
140
- - if that *id-expression* denotes a non-static data member and it
141
- appears in an unevaluated operand.
142
- \[*Example 3*:
143
  ``` cpp
144
  struct S {
145
  int m;
146
  };
147
  int i = sizeof(S::m); // OK
148
  int j = sizeof(S::m + 42); // OK
 
149
  ```
150
 
151
  — *end example*]
152
 
153
  For an *id-expression* that denotes an overload set, overload resolution
154
  is performed to select a unique function [[over.match]], [[over.over]].
155
 
156
- [*Note 3*:
157
 
158
  A program cannot refer to a function with a trailing *requires-clause*
159
  whose *constraint-expression* is not satisfied, because such functions
160
  are never selected by overload resolution.
161
 
162
- [*Example 4*:
163
 
164
  ``` cpp
165
  template<typename T> struct A {
166
  static void f(int) requires false;
167
  };
@@ -172,12 +224,12 @@ void g() {
172
  decltype(A<int>::f)* p2 = nullptr; // error: the type decltype(A<int>::f) is invalid
173
  }
174
  ```
175
 
176
  In each case, the constraints of `f` are not satisfied. In the
177
- declaration of `p2`, those constraints are required to be satisfied even
178
- though `f` is an unevaluated operand [[term.unevaluated.operand]].
179
 
180
  — *end example*]
181
 
182
  — *end note*]
183
 
@@ -188,27 +240,24 @@ unqualified-id:
188
  identifier
189
  operator-function-id
190
  conversion-function-id
191
  literal-operator-id
192
  '~' type-name
193
- '~' decltype-specifier
194
  template-id
195
  ```
196
 
197
  An *identifier* is only an *id-expression* if it has been suitably
198
- declared [[dcl.dcl]] or if it appears as part of a *declarator-id*
199
- [[dcl.decl]]. An *identifier* that names a coroutine parameter refers to
200
- the copy of the parameter [[dcl.fct.def.coroutine]].
201
 
202
  [*Note 1*: For *operator-function-id*s, see  [[over.oper]]; for
203
  *conversion-function-id*s, see  [[class.conv.fct]]; for
204
  *literal-operator-id*s, see  [[over.literal]]; for *template-id*s, see 
205
- [[temp.names]]. A *type-name* or *decltype-specifier* prefixed by `~`
206
- denotes the destructor of the type so named; see  [[expr.prim.id.dtor]].
207
- Within the definition of a non-static member function, an *identifier*
208
- that names a non-static member is transformed to a class member access
209
- expression [[class.mfct.non.static]]. — *end note*]
210
 
211
  A *component name* of an *unqualified-id* U is
212
 
213
  - U if it is a name or
214
  - the component name of the *template-id* or *type-name* of U, if any.
@@ -219,46 +268,147 @@ several component names
219
 
220
  The *terminal name* of a construct is the component name of that
221
  construct that appears lexically last.
222
 
223
  The result is the entity denoted by the *unqualified-id*
224
- [[basic.lookup.unqual]]. If the *unqualified-id* appears in a
225
- *lambda-expression* at program point P and the entity is a local entity
226
- [[basic.pre]] or a variable declared by an *init-capture*
227
- [[expr.prim.lambda.capture]], then let S be the *compound-statement* of
228
- the innermost enclosing *lambda-expression* of P. If naming the entity
229
- from outside of an unevaluated operand within S would refer to an entity
230
- captured by copy in some intervening *lambda-expression*, then let E be
231
- the innermost such *lambda-expression*.
232
-
233
- - If there is such a *lambda-expression* and if P is in E’s function
234
- parameter scope but not its *parameter-declaration-clause*, then the
235
- type of the expression is the type of a class member access expression
236
- [[expr.ref]] naming the non-static data member that would be declared
237
- for such a capture in the object parameter [[dcl.fct]] of the function
238
- call operator of E. \[*Note 3*: If E is not declared `mutable`, the
239
- type of such an identifier will typically be `const`
240
- qualified. *end note*]
241
- - Otherwise (if there is no such *lambda-expression* or if P either
242
- precedes E’s function parameter scope or is in E’s
243
- *parameter-declaration-clause*), the type of the expression is the
244
- type of the result.
245
-
246
- [*Note 4*: If the entity is a template parameter object for a template
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  parameter of type `T` [[temp.param]], the type of the expression is
248
- `const T`. — *end note*]
249
 
250
- [*Note 5*: The type will be adjusted as described in [[expr.type]] if
 
 
 
251
  it is cv-qualified or is a reference type. — *end note*]
252
 
253
  The expression is an xvalue if it is move-eligible (see below); an
254
  lvalue if the entity is a function, variable, structured binding
255
- [[dcl.struct.bind]], data member, or template parameter object; and a
256
- prvalue otherwise [[basic.lval]]; it is a bit-field if the identifier
257
- designates a bit-field.
258
 
259
- [*Example 1*:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
 
261
  ``` cpp
262
  void f() {
263
  float x, &r = x;
264
 
@@ -285,27 +435,23 @@ void f() {
285
  }
286
  ```
287
 
288
  — *end example*]
289
 
290
- An *implicitly movable entity* is a variable of automatic storage
291
  duration that is either a non-volatile object or an rvalue reference to
292
- a non-volatile object type. In the following contexts, an
293
- *id-expression* is *move-eligible*:
294
 
295
- - If the *id-expression* (possibly parenthesized) is the operand of a
296
- `return` [[stmt.return]] or `co_return` [[stmt.return.coroutine]]
297
- statement, and names an implicitly movable entity declared in the body
298
- or *parameter-declaration-clause* of the innermost enclosing function
299
- or *lambda-expression*, or
300
- - if the *id-expression* (possibly parenthesized) is the operand of a
301
- *throw-expression* [[expr.throw]], and names an implicitly movable
302
- entity that belongs to a scope that does not contain the
303
- *compound-statement* of the innermost *lambda-expression*,
304
- *try-block*, or *function-try-block* (if any) whose
305
- *compound-statement* or *ctor-initializer* contains the
306
- *throw-expression*.
307
 
308
  #### Qualified names <a id="expr.prim.id.qual">[[expr.prim.id.qual]]</a>
309
 
310
  ``` bnf
311
  qualified-id:
@@ -315,71 +461,152 @@ qualified-id:
315
  ``` bnf
316
  nested-name-specifier:
317
  '::'
318
  type-name '::'
319
  namespace-name '::'
320
- decltype-specifier '::'
 
321
  nested-name-specifier identifier '::'
322
  nested-name-specifier templateₒₚₜ simple-template-id '::'
323
  ```
324
 
 
 
 
 
 
 
325
  The component names of a *qualified-id* are those of its
326
  *nested-name-specifier* and *unqualified-id*. The component names of a
327
  *nested-name-specifier* are its *identifier* (if any) and those of its
328
  *type-name*, *namespace-name*, *simple-template-id*, and/or
329
  *nested-name-specifier*.
330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  A *nested-name-specifier* is *declarative* if it is part of
332
 
333
  - a *class-head-name*,
334
  - an *enum-head-name*,
335
  - a *qualified-id* that is the *id-expression* of a *declarator-id*, or
336
  - a declarative *nested-name-specifier*.
337
 
338
  A declarative *nested-name-specifier* shall not have a
339
- *decltype-specifier*. A declaration that uses a declarative
340
- *nested-name-specifier* shall be a friend declaration or inhabit a scope
341
- that contains the entity being redeclared or specialized.
 
342
 
343
- The *nested-name-specifier* `::` nominates the global namespace. A
344
- *nested-name-specifier* with a *decltype-specifier* nominates the type
345
- denoted by the *decltype-specifier*, which shall be a class or
346
- enumeration type. If a *nested-name-specifier* N is declarative and has
347
- a *simple-template-id* with a template argument list A that involves a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  template parameter, let T be the template nominated by N without A. T
349
  shall be a class template.
350
-
351
  - If A is the template argument list [[temp.arg]] of the corresponding
352
- *template-head* H [[temp.mem]], N nominates the primary template of T;
353
- H shall be equivalent to the *template-head* of T [[temp.over.link]].
354
- - Otherwise, N nominates the partial specialization
355
- [[temp.spec.partial]] of T whose template argument list is equivalent
356
- to A [[temp.over.link]]; the program is ill-formed if no such partial
357
- specialization exists.
358
-
359
- Any other *nested-name-specifier* nominates the entity denoted by its
360
- *type-name*, *namespace-name*, *identifier*, or *simple-template-id*. If
361
- the *nested-name-specifier* is not declarative, the entity shall not be
362
- a template.
363
 
364
  A *qualified-id* shall not be of the form *nested-name-specifier*
365
- `template`ₒₚₜ `~` *decltype-specifier* nor of the form
366
- *decltype-specifier* `::` `~` *type-name*.
367
 
368
  The result of a *qualified-id* Q is the entity it denotes
369
- [[basic.lookup.qual]]. The type of the expression is the type of the
370
- result. The result is an lvalue if the member is
 
 
 
 
 
 
 
 
 
 
 
 
 
371
 
372
  - a function other than a non-static member function,
373
  - a non-static member function if Q is the operand of a unary `&`
374
  operator,
375
  - a variable,
376
  - a structured binding [[dcl.struct.bind]], or
377
  - a data member,
378
 
379
  and a prvalue otherwise.
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  #### Destruction <a id="expr.prim.id.dtor">[[expr.prim.id.dtor]]</a>
382
 
383
  An *id-expression* that denotes the destructor of a type `T` names the
384
  destructor of `T` if `T` is a class type [[class.dtor]], otherwise the
385
  *id-expression* is said to name a *pseudo-destructor*.
@@ -426,14 +653,15 @@ lambda-introducer:
426
  ```
427
 
428
  ``` bnf
429
  lambda-declarator:
430
  lambda-specifier-seq noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
431
- noexcept-specifier attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
432
- trailing-return-typeₒₚₜ
 
433
  '(' parameter-declaration-clause ')' lambda-specifier-seqₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
434
- trailing-return-typeₒₚₜ requires-clauseₒₚₜ
435
  ```
436
 
437
  ``` bnf
438
  lambda-specifier:
439
  consteval
@@ -442,12 +670,11 @@ lambda-specifier:
442
  static
443
  ```
444
 
445
  ``` bnf
446
  lambda-specifier-seq:
447
- lambda-specifier
448
- lambda-specifier lambda-specifier-seq
449
  ```
450
 
451
  A *lambda-expression* provides a concise way to create a simple function
452
  object.
453
 
@@ -473,12 +700,24 @@ An ambiguity can arise because a *requires-clause* can end in an
473
  *attribute-specifier-seq*, which collides with the
474
  *attribute-specifier-seq* in *lambda-expression*. In such cases, any
475
  attributes are treated as *attribute-specifier-seq* in
476
  *lambda-expression*.
477
 
478
- [*Note 2*: Such ambiguous cases cannot have valid semantics because the
479
- constraint expression would not have type `bool`. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
480
 
481
  A *lambda-specifier-seq* shall contain at most one of each
482
  *lambda-specifier* and shall not contain both `constexpr` and
483
  `consteval`. If the *lambda-declarator* contains an explicit object
484
  parameter [[dcl.fct]], then no *lambda-specifier* in the
@@ -488,19 +727,20 @@ the *lambda-specifier-seq* contains `static`, there shall be no
488
  *lambda-capture*.
489
 
490
  [*Note 3*: The trailing *requires-clause* is described in
491
  [[dcl.decl]]. — *end note*]
492
 
493
- If a *lambda-declarator* does not include a
494
- *parameter-declaration-clause*, it is as if `()` were inserted at the
495
- start of the *lambda-declarator*. If the *lambda-declarator* does not
496
- include a *trailing-return-type*, it is considered to be `-> auto`.
 
497
 
498
  [*Note 4*: In that case, the return type is deduced from `return`
499
  statements as described in [[dcl.spec.auto]]. — *end note*]
500
 
501
- [*Example 2*:
502
 
503
  ``` cpp
504
  auto x1 = [](int i) { return i; }; // OK, return type is int
505
  auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from braced-init-list
506
  int j;
@@ -511,53 +751,62 @@ auto x3 = [&]()->auto&& { return j; }; // OK, return type is int&
511
 
512
  A lambda is a *generic lambda* if the *lambda-expression* has any
513
  generic parameter type placeholders [[dcl.spec.auto]], or if the lambda
514
  has a *template-parameter-list*.
515
 
516
- [*Example 3*:
517
 
518
  ``` cpp
519
- int i = [](int i, auto a) { return i; }(3, 4); // OK, a generic lambda
520
- int j = []<class T>(T t, int i) { return i; }(3, 4); // OK, a generic lambda
 
521
  ```
522
 
523
  — *end example*]
524
 
525
  #### Closure types <a id="expr.prim.lambda.closure">[[expr.prim.lambda.closure]]</a>
526
 
527
  The type of a *lambda-expression* (which is also the type of the closure
528
  object) is a unique, unnamed non-union class type, called the *closure
529
  type*, whose properties are described below.
530
 
 
 
 
531
  The closure type is declared in the smallest block scope, class scope,
532
  or namespace scope that contains the corresponding *lambda-expression*.
533
 
534
  [*Note 1*: This determines the set of namespaces and classes associated
535
  with the closure type [[basic.lookup.argdep]]. The parameter types of a
536
  *lambda-declarator* do not affect these associated namespaces and
537
  classes. — *end note*]
538
 
539
- The closure type is not an aggregate type [[dcl.init.aggr]]. An
540
- implementation may define the closure type differently from what is
541
- described below provided this does not alter the observable behavior of
542
- the program other than by changing:
 
543
 
544
  - the size and/or alignment of the closure type,
545
- - whether the closure type is trivially copyable [[class.prop]], or
 
 
546
  - whether the closure type is a standard-layout class [[class.prop]].
547
 
548
  An implementation shall not add members of rvalue reference type to the
549
  closure type.
550
 
551
  The closure type for a *lambda-expression* has a public inline function
552
  call operator (for a non-generic lambda) or function call operator
553
  template (for a generic lambda) [[over.call]] whose parameters and
554
- return type are described by the *lambda-expression*s
555
  *parameter-declaration-clause* and *trailing-return-type* respectively,
556
  and whose *template-parameter-list* consists of the specified
557
- *template-parameter-list*, if any. The *requires-clause* of the function
558
- call operator template is the *requires-clause* immediately following
 
 
559
  `<` *template-parameter-list* `>`, if any. The trailing
560
  *requires-clause* of the function call operator or operator template is
561
  the *requires-clause* of the *lambda-declarator*, if any.
562
 
563
  [*Note 2*: The function call operator template for a generic lambda can
@@ -594,11 +843,12 @@ std::cout << fact(5); // OK, outputs 1
594
  Given a lambda with a *lambda-capture*, the type of the explicit object
595
  parameter, if any, of the lambda’s function call operator (possibly
596
  instantiated from a function call operator template) shall be either:
597
 
598
  - the closure type,
599
- - a class type derived from the closure type, or
 
600
  - a reference to a possibly cv-qualified such type.
601
 
602
  [*Example 2*:
603
 
604
  ``` cpp
@@ -622,13 +872,14 @@ function or static member function template [[class.static.mfct]] if the
622
  `static`. Otherwise, it is a non-static member function or member
623
  function template [[class.mfct.non.static]] that is declared `const`
624
  [[class.mfct.non.static]] if and only if the *lambda-expression*’s
625
  *parameter-declaration-clause* is not followed by `mutable` and the
626
  *lambda-declarator* does not contain an explicit object parameter. It is
627
- neither virtual nor declared `volatile`. Any *noexcept-specifier*
628
- specified on a *lambda-expression* applies to the corresponding function
629
- call operator or operator template. An *attribute-specifier-seq* in a
 
630
  *lambda-declarator* appertains to the type of the corresponding function
631
  call operator or operator template. An *attribute-specifier-seq* in a
632
  *lambda-expression* preceding a *lambda-declarator* appertains to the
633
  corresponding function call operator or operator template. The function
634
  call operator or any given operator template specialization is a
@@ -707,35 +958,80 @@ auto f = []<typename T1, C1 T2> requires C2<sizeof(T1) + sizeof(T2)>
707
 
708
  — *end example*]
709
 
710
  — *end note*]
711
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
712
  The closure type for a non-generic *lambda-expression* with no
713
- *lambda-capture* whose constraints (if any) are satisfied has a
714
- conversion function to pointer to function with C++ language linkage
715
- [[dcl.link]] having the same parameter and return types as the closure
716
- type’s function call operator. The conversion is to “pointer to
717
- `noexcept` function” if the function call operator has a non-throwing
718
- exception specification. If the function call operator is a static
719
- member function, then the value returned by this conversion function is
720
- the address of the function call operator. Otherwise, the value returned
721
- by this conversion function is the address of a function `F` that, when
722
- invoked, has the same effect as invoking the closure type’s function
723
- call operator on a default-constructed instance of the closure type. `F`
724
- is a constexpr function if the function call operator is a constexpr
725
- function and is an immediate function if the function call operator is
726
- an immediate function.
 
727
 
728
- For a generic lambda with no *lambda-capture*, the closure type has a
729
- conversion function template to pointer to function. The conversion
730
- function template has the same invented template parameter list, and the
731
- pointer to function has the same parameter types, as the function call
732
- operator template. The return type of the pointer to function shall
733
- behave as if it were a *decltype-specifier* denoting the return type of
734
- the corresponding function call operator template specialization.
 
735
 
736
- [*Note 4*:
737
 
738
  If the generic lambda has no *trailing-return-type* or the
739
  *trailing-return-type* contains a placeholder type, return type
740
  deduction of the corresponding function call operator template
741
  specialization has to be done. The corresponding specialization is that
@@ -767,11 +1063,11 @@ struct Closure {
767
  };
768
  ```
769
 
770
  — *end note*]
771
 
772
- [*Example 6*:
773
 
774
  ``` cpp
775
  void f1(int (*)(int)) { }
776
  void f2(char (*)(int)) { }
777
 
@@ -791,27 +1087,26 @@ int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
791
 
792
  — *end example*]
793
 
794
  If the function call operator template is a static member function
795
  template, then the value returned by any given specialization of this
796
- conversion function template is the address of the corresponding
797
- function call operator template specialization. Otherwise, the value
798
- returned by any given specialization of this conversion function
799
- template is the address of a function `F` that, when invoked, has the
800
- same effect as invoking the generic lambda’s corresponding function call
801
- operator template specialization on a default-constructed instance of
802
- the closure type. `F` is a constexpr function if the corresponding
803
- specialization is a constexpr function and `F` is an immediate function
804
- if the function call operator template specialization is an immediate
805
- function.
806
 
807
- [*Note 5*: This will result in the implicit instantiation of the
808
  generic lambda’s body. The instantiated generic lambda’s return type and
809
- parameter types are required to match the return type and parameter
810
- types of the pointer to function. — *end note*]
811
 
812
- [*Example 7*:
813
 
814
  ``` cpp
815
  auto GL = [](auto a) { std::cout << a; return a; };
816
  int (*GL_int)(int) = GL; // OK, through conversion function template
817
  GL_int(3); // OK, same as GL(3)
@@ -821,11 +1116,11 @@ GL_int(3); // OK, same as GL(3)
821
 
822
  The conversion function or conversion function template is public,
823
  constexpr, non-virtual, non-explicit, const, and has a non-throwing
824
  exception specification [[except.spec]].
825
 
826
- [*Example 8*:
827
 
828
  ``` cpp
829
  auto Fwd = [](int (*fp)(int), auto a) { return fp(a); };
830
  auto C = [](auto a) { return a; };
831
 
@@ -840,11 +1135,11 @@ static_assert(Fwd(NC,3) == 3); // error
840
 
841
  The *lambda-expression*’s *compound-statement* yields the
842
  *function-body* [[dcl.fct.def]] of the function call operator, but it is
843
  not within the scope of the closure type.
844
 
845
- [*Example 9*:
846
 
847
  ``` cpp
848
  struct S1 {
849
  int x, y;
850
  int operator()(int);
@@ -857,23 +1152,25 @@ struct S1 {
857
  };
858
  ```
859
 
860
  — *end example*]
861
 
862
- Further, a variable `__func__` is implicitly defined at the beginning of
863
- the *compound-statement* of the *lambda-expression*, with semantics as
864
- described in  [[dcl.fct.def.general]].
 
 
865
 
866
  The closure type associated with a *lambda-expression* has no default
867
  constructor if the *lambda-expression* has a *lambda-capture* and a
868
  defaulted default constructor otherwise. It has a defaulted copy
869
  constructor and a defaulted move constructor [[class.copy.ctor]]. It has
870
  a deleted copy assignment operator if the *lambda-expression* has a
871
  *lambda-capture* and defaulted copy and move assignment operators
872
  otherwise [[class.copy.assign]].
873
 
874
- [*Note 6*: These special member functions are implicitly defined as
875
  usual, which can result in them being defined as deleted. — *end note*]
876
 
877
  The closure type associated with a *lambda-expression* has an
878
  implicitly-declared destructor [[class.dtor]].
879
 
@@ -911,30 +1208,30 @@ capture:
911
  ``` bnf
912
  simple-capture:
913
  identifier '...'ₒₚₜ
914
  '&' identifier '...'ₒₚₜ
915
  this
916
- '*' 'this'
917
  ```
918
 
919
  ``` bnf
920
  init-capture:
921
  '...'ₒₚₜ identifier initializer
922
  '&' '...'ₒₚₜ identifier initializer
923
  ```
924
 
925
  The body of a *lambda-expression* may refer to local entities of
926
- enclosing block scopes by capturing those entities, as described below.
927
 
928
  If a *lambda-capture* includes a *capture-default* that is `&`, no
929
  identifier in a *simple-capture* of that *lambda-capture* shall be
930
  preceded by `&`. If a *lambda-capture* includes a *capture-default* that
931
  is `=`, each *simple-capture* of that *lambda-capture* shall be of the
932
  form “`&` *identifier* `...`ₒₚₜ ”, “`this`”, or “`* this`”.
933
 
934
  [*Note 1*: The form `[&,this]` is redundant but accepted for
935
- compatibility with ISO C++14. — *end note*]
936
 
937
  Ignoring appearances in *initializer*s of *init-capture*s, an identifier
938
  or `this` shall not appear more than once in a *lambda-capture*.
939
 
940
  [*Example 1*:
@@ -953,14 +1250,19 @@ void S2::f(int i) {
953
  ```
954
 
955
  — *end example*]
956
 
957
  A *lambda-expression* shall not have a *capture-default* or
958
- *simple-capture* in its *lambda-introducer* unless its innermost
959
- enclosing scope is a block scope [[basic.scope.block]] or it appears
960
- within a default member initializer and its innermost enclosing scope is
961
- the corresponding class scope [[basic.scope.class]].
 
 
 
 
 
962
 
963
  The *identifier* in a *simple-capture* shall denote a local entity
964
  [[basic.lookup.unqual]], [[basic.pre]]. The *simple-capture*s `this` and
965
  `* this` denote the local entity `*this`. An entity that is designated
966
  by a *simple-capture* is said to be *explicitly captured*.
@@ -1178,11 +1480,12 @@ void f2() {
1178
  An entity is *captured by copy* if
1179
 
1180
  - it is implicitly captured, the *capture-default* is `=`, and the
1181
  captured entity is not `*this`, or
1182
  - it is explicitly captured with a capture that is not of the form
1183
- `this`, `&` *identifier*, or `&` *identifier* *initializer*.
 
1184
 
1185
  For each entity captured by copy, an unnamed non-static data member is
1186
  declared in the closure type. The declaration order of these members is
1187
  unspecified. The type of such a data member is the referenced type if
1188
  the entity is a reference to an object, an lvalue reference to the
@@ -1209,11 +1512,11 @@ the closure type.
1209
  ``` cpp
1210
  void f(const int*);
1211
  void g() {
1212
  const int N = 10;
1213
  [=] {
1214
- int arr[N]; // OK, not an odr-use, refers to automatic variable
1215
  f(&N); // OK, causes N to be captured; &N points to
1216
  // the corresponding member of the closure type
1217
  };
1218
  }
1219
  ```
@@ -1380,10 +1683,12 @@ bool f(Args ...args) {
1380
  }
1381
  ```
1382
 
1383
  — *end example*]
1384
 
 
 
1385
  ### Requires expressions <a id="expr.prim.req">[[expr.prim.req]]</a>
1386
 
1387
  #### General <a id="expr.prim.req.general">[[expr.prim.req.general]]</a>
1388
 
1389
  A *requires-expression* provides a concise way to express requirements
@@ -1405,12 +1710,11 @@ requirement-body:
1405
  '{' requirement-seq '}'
1406
  ```
1407
 
1408
  ``` bnf
1409
  requirement-seq:
1410
- requirement
1411
- requirement requirement-seq
1412
  ```
1413
 
1414
  ``` bnf
1415
  requirement:
1416
  simple-requirement
@@ -1418,12 +1722,11 @@ requirement:
1418
  compound-requirement
1419
  nested-requirement
1420
  ```
1421
 
1422
  A *requires-expression* is a prvalue of type `bool` whose value is
1423
- described below. Expressions appearing within a *requirement-body* are
1424
- unevaluated operands [[term.unevaluated.operand]].
1425
 
1426
  [*Example 1*:
1427
 
1428
  A common use of *requires-expression*s is to define requirements in
1429
  concepts such as the one below:
@@ -1450,38 +1753,43 @@ The first `requires` introduces the *requires-clause*, and the second
1450
  introduces the *requires-expression*.
1451
 
1452
  — *end example*]
1453
 
1454
  A *requires-expression* may introduce local parameters using a
1455
- *parameter-declaration-clause* [[dcl.fct]]. A local parameter of a
1456
- *requires-expression* shall not have a default argument. These
1457
- parameters have no linkage, storage, or lifetime; they are only used as
1458
- notation for the purpose of defining *requirement*s. The
1459
- *parameter-declaration-clause* of a *requirement-parameter-list* shall
1460
- not terminate with an ellipsis.
 
1461
 
1462
  [*Example 2*:
1463
 
1464
  ``` cpp
1465
  template<typename T>
1466
  concept C = requires(T t, ...) { // error: terminates with an ellipsis
1467
  t;
1468
  };
 
 
 
 
1469
  ```
1470
 
1471
  — *end example*]
1472
 
1473
- The substitution of template arguments into a *requires-expression* may
1474
- result in the formation of invalid types or expressions in its
1475
- *requirement*s or the violation of the semantic constraints of those
1476
- *requirement*s. In such cases, the *requires-expression* evaluates to
1477
- `false`; it does not cause the program to be ill-formed. The
1478
- substitution and semantic constraint checking proceeds in lexical order
1479
- and stops when a condition that determines the result of the
1480
- *requires-expression* is encountered. If substitution (if any) and
1481
- semantic constraint checking succeed, the *requires-expression*
1482
- evaluates to `true`.
1483
 
1484
  [*Note 1*: If a *requires-expression* contains invalid types or
1485
  expressions in its *requirement*s, and it does not appear within the
1486
  declaration of a templated entity, then the program is
1487
  ill-formed. — *end note*]
@@ -1493,11 +1801,11 @@ diagnostic required.
1493
  [*Example 3*:
1494
 
1495
  ``` cpp
1496
  template<typename T> concept C =
1497
  requires {
1498
- new int[-(int)sizeof(T)]; // ill-formed, no diagnostic required
1499
  };
1500
  ```
1501
 
1502
  — *end example*]
1503
 
@@ -1506,16 +1814,16 @@ requires {
1506
  ``` bnf
1507
  simple-requirement:
1508
  expression ';'
1509
  ```
1510
 
1511
- A *simple-requirement* asserts the validity of an *expression*.
 
1512
 
1513
  [*Note 1*: The enclosing *requires-expression* will evaluate to `false`
1514
- if substitution of template arguments into the *expression* fails. The
1515
- *expression* is an unevaluated operand
1516
- [[term.unevaluated.operand]]. — *end note*]
1517
 
1518
  [*Example 1*:
1519
 
1520
  ``` cpp
1521
  template<typename T> concept C =
@@ -1535,13 +1843,17 @@ as a *simple-requirement*.
1535
  #### Type requirements <a id="expr.prim.req.type">[[expr.prim.req.type]]</a>
1536
 
1537
  ``` bnf
1538
  type-requirement:
1539
  typename nested-name-specifierₒₚₜ type-name ';'
 
 
1540
  ```
1541
 
1542
- A *type-requirement* asserts the validity of a type.
 
 
1543
 
1544
  [*Note 1*: The enclosing *requires-expression* will evaluate to `false`
1545
  if substitution of template arguments fails. — *end note*]
1546
 
1547
  [*Example 1*:
@@ -1550,13 +1862,15 @@ if substitution of template arguments fails. — *end note*]
1550
  template<typename T, typename T::type = 0> struct S;
1551
  template<typename T> using Ref = T&;
1552
 
1553
  template<typename T> concept C = requires {
1554
  typename T::inner; // required nested member name
1555
- typename S<T>; // required valid[temp.names] template-id;
1556
- // fails if T::type does not exist as a type to which 0 can be implicitly converted
1557
  typename Ref<T>; // required alias template substitution, fails if T is void
 
 
1558
  };
1559
  ```
1560
 
1561
  — *end example*]
1562
 
@@ -1573,13 +1887,14 @@ compound-requirement:
1573
  ``` bnf
1574
  return-type-requirement:
1575
  '->' type-constraint
1576
  ```
1577
 
1578
- A *compound-requirement* asserts properties of the *expression* E.
1579
- Substitution of template arguments (if any) and verification of semantic
1580
- properties proceed in the following order:
 
1581
 
1582
  - Substitution of template arguments (if any) into the *expression* is
1583
  performed.
1584
  - If the `noexcept` specifier is present, E shall not be a
1585
  potentially-throwing expression [[except.spec]].
@@ -1669,5 +1984,110 @@ template<typename T> concept D = requires (T t) {
1669
  `D<T>` is satisfied if `sizeof(decltype (+t)) == 1`
1670
  [[temp.constr.atomic]].
1671
 
1672
  — *end example*]
1673
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ## Primary expressions <a id="expr.prim">[[expr.prim]]</a>
2
 
3
+ ### Grammar <a id="expr.prim.grammar">[[expr.prim.grammar]]</a>
4
+
5
  ``` bnf
6
  primary-expression:
7
  literal
8
  this
9
  '(' expression ')'
10
  id-expression
11
  lambda-expression
12
  fold-expression
13
  requires-expression
14
+ splice-expression
15
  ```
16
 
17
  ### Literals <a id="expr.prim.literal">[[expr.prim.literal]]</a>
18
 
19
  The type of a *literal* is determined based on its form as specified in
 
33
  innermost class scope containing that point.
34
 
35
  [*Note 1*: A *lambda-expression* does not introduce a class
36
  scope. — *end note*]
37
 
38
+ If the expression `this` appears within the predicate of a contract
39
+ assertion [[basic.contract.general]] (including as the result of an
40
+ implicit transformation [[expr.prim.id.general]] and including in the
41
+ bodies of nested *lambda-expression*s) and the current class encloses
42
+ the contract assertion, `const` is combined with the *cv-qualifier-seq*
43
+ used to generate the resulting type (see below).
44
+
45
  If a declaration declares a member function or member function template
46
  of a class `X`, the expression `this` is a prvalue of type “pointer to
47
  *cv-qualifier-seq* `X`” wherever `X` is the current class between the
48
  optional *cv-qualifier-seq* and the end of the *function-definition*,
49
  *member-declarator*, or *declarator*. It shall not appear within the
50
+ declaration of a static or explicit object member function of the
51
+ current class (although its type and value category are defined within
52
+ such member functions as they are within an implicit object member
53
+ function).
54
 
55
  [*Note 2*: This is because declaration matching does not occur until
56
  the complete declarator is known. — *end note*]
57
 
58
  [*Note 3*:
 
116
 
117
  ``` bnf
118
  id-expression:
119
  unqualified-id
120
  qualified-id
121
+ pack-index-expression
122
  ```
123
 
124
  An *id-expression* is a restricted form of a *primary-expression*.
125
 
126
  [*Note 1*: An *id-expression* can appear after `.` and `->` operators
127
  [[expr.ref]]. — *end note*]
128
 
129
+ If an *id-expression* E denotes a non-static non-type member of some
130
+ class `C` at a point where the current class [[expr.prim.this]] is `X`
131
+ and
132
+
133
+ - E is potentially evaluated or `C` is `X` or a base class of `X`, and
134
+ - E is not the *id-expression* of a class member access expression
135
+ [[expr.ref]], and
136
+ - E is not the *id-expression* of a *reflect-expression*
137
+ [[expr.reflect]], and
138
+ - if E is a *qualified-id*, E is not the un-parenthesized operand of the
139
+ unary `&` operator [[expr.unary.op]],
140
+
141
+ the *id-expression* is transformed into a class member access expression
142
+ using `(*this)` as the object expression. If this transformation occurs
143
+ in the predicate of a precondition assertion of a constructor of `X` or
144
+ a postcondition assertion of a destructor of `X`, the expression is
145
+ ill-formed.
146
+
147
+ [*Note 2*: If `C` is not `X` or a base class of `X`, the class member
148
+ access expression is ill-formed. Also, if the *id-expression* occurs
149
+ within a static or explicit object member function, the class member
150
+ access is ill-formed. — *end note*]
151
+
152
+ This transformation does not apply in the template definition context
153
+ [[temp.dep.type]].
154
+
155
+ [*Example 1*:
156
+
157
+ ``` cpp
158
+ struct C {
159
+ bool b;
160
+ C() pre(b) // error
161
+ pre(&this->b) // OK
162
+ pre(sizeof(b) > 0); // OK, b is not potentially evaluated.
163
+ };
164
+ ```
165
+
166
+ — *end example*]
167
+
168
  If an *id-expression* E denotes a member M of an anonymous union
169
  [[class.union.anon]] U:
170
 
171
  - If U is a non-static data member, E refers to M as a member of the
172
+ lookup context of the terminal name of E (after any implicit
173
+ transformation to a class member access expression).
174
+ \[*Example 2*: `o.x` is interpreted as `o.u.x`, where u names the
175
  anonymous union member. — *end example*]
176
  - Otherwise, E is interpreted as a class member access [[expr.ref]] that
177
  designates the member subobject M of the anonymous union variable for
178
+ U. \[*Note 3*: Under this interpretation, E no longer denotes a
179
+ non-static data member. — *end note*] \[*Example 3*: `N::x` is
180
  interpreted as `N::u.x`, where u names the anonymous union
181
  variable. — *end example*]
182
 
183
+ An *id-expression* or *splice-expression* that designates a non-static
184
+ data member or implicit object member function of a class can only be
185
+ used:
186
 
187
+ - as part of a class member access (after any implicit transformation
188
+ (see above)) in which the object expression refers to the member’s
189
+ class or a class derived from that class, or
190
  - to form a pointer to member [[expr.unary.op]], or
191
+ - if that *id-expression* or *splice-expression* designates a non-static
192
+ data member and it appears in an unevaluated operand.
193
+ \[*Example 4*:
194
  ``` cpp
195
  struct S {
196
  int m;
197
  };
198
  int i = sizeof(S::m); // OK
199
  int j = sizeof(S::m + 42); // OK
200
+ int S::*k = &[:^^S::m:]; // OK
201
  ```
202
 
203
  — *end example*]
204
 
205
  For an *id-expression* that denotes an overload set, overload resolution
206
  is performed to select a unique function [[over.match]], [[over.over]].
207
 
208
+ [*Note 4*:
209
 
210
  A program cannot refer to a function with a trailing *requires-clause*
211
  whose *constraint-expression* is not satisfied, because such functions
212
  are never selected by overload resolution.
213
 
214
+ [*Example 5*:
215
 
216
  ``` cpp
217
  template<typename T> struct A {
218
  static void f(int) requires false;
219
  };
 
224
  decltype(A<int>::f)* p2 = nullptr; // error: the type decltype(A<int>::f) is invalid
225
  }
226
  ```
227
 
228
  In each case, the constraints of `f` are not satisfied. In the
229
+ declaration of `p2`, those constraints need to be satisfied even though
230
+ `f` is an unevaluated operand [[term.unevaluated.operand]].
231
 
232
  — *end example*]
233
 
234
  — *end note*]
235
 
 
240
  identifier
241
  operator-function-id
242
  conversion-function-id
243
  literal-operator-id
244
  '~' type-name
245
+ '~' computed-type-specifier
246
  template-id
247
  ```
248
 
249
  An *identifier* is only an *id-expression* if it has been suitably
250
+ declared [[dcl]] or if it appears as part of a *declarator-id*
251
+ [[dcl.decl]].
 
252
 
253
  [*Note 1*: For *operator-function-id*s, see  [[over.oper]]; for
254
  *conversion-function-id*s, see  [[class.conv.fct]]; for
255
  *literal-operator-id*s, see  [[over.literal]]; for *template-id*s, see 
256
+ [[temp.names]]. A *type-name* or *computed-type-specifier* prefixed by
257
+ `~` denotes the destructor of the type so named; see 
258
+ [[expr.prim.id.dtor]]. *end note*]
 
 
259
 
260
  A *component name* of an *unqualified-id* U is
261
 
262
  - U if it is a name or
263
  - the component name of the *template-id* or *type-name* of U, if any.
 
268
 
269
  The *terminal name* of a construct is the component name of that
270
  construct that appears lexically last.
271
 
272
  The result is the entity denoted by the *unqualified-id*
273
+ [[basic.lookup.unqual]].
274
+
275
+ If
276
+
277
+ - the *unqualified-id* appears in a *lambda-expression* at program point
278
+ P,
279
+ - the entity is a local entity [[basic.pre]] or a variable declared by
280
+ an *init-capture* [[expr.prim.lambda.capture]],
281
+ - naming the entity within the *compound-statement* of the innermost
282
+ enclosing *lambda-expression* of P, but not in an unevaluated operand,
283
+ would refer to an entity captured by copy in some intervening
284
+ *lambda-expression*, and
285
+ - P is in the function parameter scope, but not the
286
+ *parameter-declaration-clause*, of the innermost such
287
+ *lambda-expression* E,
288
+
289
+ then the type of the expression is the type of a class member access
290
+ expression [[expr.ref]] naming the non-static data member that would be
291
+ declared for such a capture in the object parameter [[dcl.fct]] of the
292
+ function call operator of E.
293
+
294
+ [*Note 3*: If E is not declared `mutable`, the type of such an
295
+ identifier will typically be `const` qualified. *end note*]
296
+
297
+ Otherwise, if the *unqualified-id* names a coroutine parameter, the type
298
+ of the expression is that of the copy of the parameter
299
+ [[dcl.fct.def.coroutine]], and the result is that copy.
300
+
301
+ Otherwise, if the *unqualified-id* names a result binding
302
+ [[dcl.contract.res]] attached to a function with return type `U`,
303
+
304
+ - if `U` is “reference to `T`”, then the type of the expression is
305
+ `const T`;
306
+ - otherwise, the type of the expression is `const U`.
307
+
308
+ Otherwise, if the *unqualified-id* appears in the predicate of a
309
+ contract assertion C [[basic.contract]] and the entity is
310
+
311
+ - a variable declared outside of C of object type `T`,
312
+ - a variable or template parameter declared outside of C of type
313
+ “reference to `T`”, or
314
+ - a structured binding of type `T` whose corresponding variable is
315
+ declared outside of C,
316
+
317
+ then the type of the expression is `const` `T`.
318
+
319
+ [*Example 1*:
320
+
321
+ ``` cpp
322
+ int n = 0;
323
+ struct X { bool m(); };
324
+
325
+ struct Y {
326
+ int z = 0;
327
+
328
+ void f(int i, int* p, int& r, X x, X* px)
329
+ pre (++n) // error: attempting to modify const lvalue
330
+ pre (++i) // error: attempting to modify const lvalue
331
+ pre (++(*p)) // OK
332
+ pre (++r) // error: attempting to modify const lvalue
333
+ pre (x.m()) // error: calling non-const member function
334
+ pre (px->m()) // OK
335
+ pre ([=,&i,*this] mutable {
336
+ ++n; // error: attempting to modify const lvalue
337
+ ++i; // error: attempting to modify const lvalue
338
+ ++p; // OK, refers to member of closure type
339
+ ++r; // OK, refers to non-reference member of closure type
340
+ ++this->z; // OK, captured *this
341
+ ++z; // OK, captured *this
342
+ int j = 17;
343
+ [&]{
344
+ int k = 34;
345
+ ++i; // error: attempting to modify const lvalue
346
+ ++j; // OK
347
+ ++k; // OK
348
+ }();
349
+ return true;
350
+ }());
351
+
352
+ template <int N, int& R, int* P>
353
+ void g()
354
+ pre(++N) // error: attempting to modify prvalue
355
+ pre(++R) // error: attempting to modify const lvalue
356
+ pre(++(*P)); // OK
357
+
358
+ int h()
359
+ post(r : ++r) // error: attempting to modify const lvalue
360
+ post(r: [=] mutable {
361
+ ++r; // OK, refers to member of closure type
362
+ return true;
363
+ }());
364
+
365
+ int& k()
366
+ post(r : ++r); // error: attempting to modify const lvalue
367
+ };
368
+ ```
369
+
370
+ — *end example*]
371
+
372
+ Otherwise, if the entity is a template parameter object for a template
373
  parameter of type `T` [[temp.param]], the type of the expression is
374
+ `const T`.
375
 
376
+ In all other cases, the type of the expression is the type of the
377
+ entity.
378
+
379
+ [*Note 4*: The type will be adjusted as described in [[expr.type]] if
380
  it is cv-qualified or is a reference type. — *end note*]
381
 
382
  The expression is an xvalue if it is move-eligible (see below); an
383
  lvalue if the entity is a function, variable, structured binding
384
+ [[dcl.struct.bind]], result binding [[dcl.contract.res]], data member,
385
+ or template parameter object; and a prvalue otherwise [[basic.lval]]; it
386
+ is a bit-field if the identifier designates a bit-field.
387
 
388
+ If an *id-expression* E appears in the predicate of a function contract
389
+ assertion attached to a function *f* and denotes a function parameter of
390
+ *f* and the implementation introduces any temporary objects to hold the
391
+ value of that parameter as specified in [[class.temporary]],
392
+
393
+ - if the contract assertion is a precondition assertion and the
394
+ evaluation of the precondition assertion is sequenced before the
395
+ initialization of the parameter object, E refers to the most recently
396
+ initialized such temporary object, and
397
+ - if the contract assertion is a postcondition assertion, it is
398
+ unspecified whether E refers to one of the temporary objects or the
399
+ parameter object; the choice is consistent within a single evaluation
400
+ of a postcondition assertion.
401
+
402
+ If an *id-expression* E names a result binding in a postcondition
403
+ assertion and the implementation introduces any temporary objects to
404
+ hold the result object as specified in [[class.temporary]], and the
405
+ postcondition assertion is sequenced before the initialization of the
406
+ result object [[expr.call]], E refers to the most recently initialized
407
+ such temporary object.
408
+
409
+ [*Example 2*:
410
 
411
  ``` cpp
412
  void f() {
413
  float x, &r = x;
414
 
 
435
  }
436
  ```
437
 
438
  — *end example*]
439
 
440
+ An *implicitly movable entity* is a variable with automatic storage
441
  duration that is either a non-volatile object or an rvalue reference to
442
+ a non-volatile object type. An *id-expression* or *splice-expression*
443
+ [[expr.prim.splice]] is *move-eligible* if
444
 
445
+ - it designates an implicitly movable entity,
446
+ - it is the (possibly parenthesized) operand of a `return`
447
+ [[stmt.return]] or `co_return` [[stmt.return.coroutine]] statement or
448
+ of a *throw-expression* [[expr.throw]], and
449
+ - each intervening scope between the declaration of the entity and the
450
+ innermost enclosing scope of the expression is a block scope and, for
451
+ a *throw-expression*, is not the block scope of a *try-block* or
452
+ *function-try-block*.
 
 
 
 
453
 
454
  #### Qualified names <a id="expr.prim.id.qual">[[expr.prim.id.qual]]</a>
455
 
456
  ``` bnf
457
  qualified-id:
 
461
  ``` bnf
462
  nested-name-specifier:
463
  '::'
464
  type-name '::'
465
  namespace-name '::'
466
+ computed-type-specifier '::'
467
+ splice-scope-specifier '::'
468
  nested-name-specifier identifier '::'
469
  nested-name-specifier templateₒₚₜ simple-template-id '::'
470
  ```
471
 
472
+ ``` bnf
473
+ splice-scope-specifier:
474
+ splice-specifier
475
+ templateₒₚₜ splice-specialization-specifier
476
+ ```
477
+
478
  The component names of a *qualified-id* are those of its
479
  *nested-name-specifier* and *unqualified-id*. The component names of a
480
  *nested-name-specifier* are its *identifier* (if any) and those of its
481
  *type-name*, *namespace-name*, *simple-template-id*, and/or
482
  *nested-name-specifier*.
483
 
484
+ A *splice-specifier* or *splice-specialization-specifier* that is not
485
+ followed by `::` is never interpreted as part of a
486
+ *splice-scope-specifier*. The keyword `template` may only be omitted
487
+ from the form `\opt{template} splice-specialization-specifier ::` when
488
+ the *splice-specialization-specifier* is preceded by `typename`.
489
+
490
+ [*Example 1*:
491
+
492
+ ``` cpp
493
+ template<int V>
494
+ struct TCls {
495
+ static constexpr int s = V;
496
+ using type = int;
497
+ };
498
+
499
+ int v1 = [:^^TCls<1>:]::s;
500
+ int v2 = template [:^^TCls:]<2>::s; // OK, template binds to splice-scope-specifier
501
+ typename [:^^TCls:]<3>::type v3 = 3; // OK, typename binds to the qualified name
502
+ template [:^^TCls:]<3>::type v4 = 4; // OK, template binds to the splice-scope-specifier
503
+ typename template [:^^TCls:]<3>::type v5 = 5; // OK, same as v3
504
+ [:^^TCls:]<3>::type v6 = 6; // error: unexpected <
505
+ ```
506
+
507
+ — *end example*]
508
+
509
  A *nested-name-specifier* is *declarative* if it is part of
510
 
511
  - a *class-head-name*,
512
  - an *enum-head-name*,
513
  - a *qualified-id* that is the *id-expression* of a *declarator-id*, or
514
  - a declarative *nested-name-specifier*.
515
 
516
  A declarative *nested-name-specifier* shall not have a
517
+ *computed-type-specifier* or a *splice-scope-specifier*. A declaration
518
+ that uses a declarative *nested-name-specifier* shall be a friend
519
+ declaration or inhabit a scope that contains the entity being redeclared
520
+ or specialized.
521
 
522
+ The entity designated by a *nested-name-specifier* is determined as
523
+ follows:
524
+
525
+ - The *nested-name-specifier* `::` designates the global namespace.
526
+ - A *nested-name-specifier* with a *computed-type-specifier* designates
527
+ the same type designated by the *computed-type-specifier*, which shall
528
+ be a class or enumeration type.
529
+ - For a *nested-name-specifier* of the form `splice-specifier ::`, the
530
+ *splice-specifier* shall designate a class or enumeration type or a
531
+ namespace. The *nested-name-specifier* designates the same entity as
532
+ the *splice-specifier*.
533
+ - For a *nested-name-specifier* of the form
534
+ `\opt{template} splice-specialization-specifier ::`, the
535
+ *splice-specifier* of the *splice-specialization-specifier* shall
536
+ designate a class template or an alias template T. Letting S be the
537
+ specialization of T corresponding to the template argument list of the
538
+ *splice-specialization-specifier*, S shall either be a class template
539
+ specialization or an alias template specialization that denotes a
540
+ class or enumeration type. The *nested-name-specifier* designates the
541
+ underlying entity of S.
542
+ - If a *nested-name-specifier* N is declarative and has a
543
+ *simple-template-id* with a template argument list A that involves a
544
  template parameter, let T be the template nominated by N without A. T
545
  shall be a class template.
 
546
  - If A is the template argument list [[temp.arg]] of the corresponding
547
+ *template-head* H [[temp.mem]], N designates the primary template of
548
+ T; H shall be equivalent to the *template-head* of T
549
+ [[temp.over.link]].
550
+ - Otherwise, N designates the partial specialization
551
+ [[temp.spec.partial]] of T whose template argument list is
552
+ equivalent to A [[temp.over.link]]; the program is ill-formed if no
553
+ such partial specialization exists.
554
+ - Any other *nested-name-specifier* designates the entity denotes by its
555
+ *type-name*, *namespace-name*, *identifier*, or *simple-template-id*.
556
+ If the *nested-name-specifier* is not declarative, the entity shall
557
+ not be a template.
558
 
559
  A *qualified-id* shall not be of the form *nested-name-specifier*
560
+ `template`ₒₚₜ `~` *computed-type-specifier* nor of the form
561
+ *computed-type-specifier* `::` `~` *type-name*.
562
 
563
  The result of a *qualified-id* Q is the entity it denotes
564
+ [[basic.lookup.qual]].
565
+
566
+ If Q appears in the predicate of a contract assertion C
567
+ [[basic.contract]] and the entity is
568
+
569
+ - a variable declared outside of C of object type `T`,
570
+ - a variable declared outside of C of type “reference to `T`”, or
571
+ - a structured binding of type `T` whose corresponding variable is
572
+ declared outside of C,
573
+
574
+ then the type of the expression is `const` `T`.
575
+
576
+ Otherwise, the type of the expression is the type of the result.
577
+
578
+ The result is an lvalue if the member is
579
 
580
  - a function other than a non-static member function,
581
  - a non-static member function if Q is the operand of a unary `&`
582
  operator,
583
  - a variable,
584
  - a structured binding [[dcl.struct.bind]], or
585
  - a data member,
586
 
587
  and a prvalue otherwise.
588
 
589
+ #### Pack indexing expression <a id="expr.prim.pack.index">[[expr.prim.pack.index]]</a>
590
+
591
+ ``` bnf
592
+ pack-index-expression:
593
+ id-expression '...' '[' constant-expression ']'
594
+ ```
595
+
596
+ The *id-expression* P in a *pack-index-expression* shall be an
597
+ *identifier* that denotes a pack.
598
+
599
+ The *constant-expression* shall be a converted constant expression
600
+ [[expr.const]] of type `std::size_t` whose value V, termed the index, is
601
+ such that 0 ≤ V < `sizeof...($P$)`.
602
+
603
+ A *pack-index-expression* is a pack expansion [[temp.variadic]].
604
+
605
+ [*Note 1*: A *pack-index-expression* denotes the Vᵗʰ element of the
606
+ pack. — *end note*]
607
+
608
  #### Destruction <a id="expr.prim.id.dtor">[[expr.prim.id.dtor]]</a>
609
 
610
  An *id-expression* that denotes the destructor of a type `T` names the
611
  destructor of `T` if `T` is a class type [[class.dtor]], otherwise the
612
  *id-expression* is said to name a *pseudo-destructor*.
 
653
  ```
654
 
655
  ``` bnf
656
  lambda-declarator:
657
  lambda-specifier-seq noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
658
+ function-contract-specifier-seqₒₚₜ
659
+ noexcept-specifier attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ function-contract-specifier-seqₒₚₜ
660
+ trailing-return-typeₒₚₜ function-contract-specifier-seqₒₚₜ
661
  '(' parameter-declaration-clause ')' lambda-specifier-seqₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
662
+ trailing-return-typeₒₚₜ requires-clauseₒₚₜ function-contract-specifier-seqₒₚₜ
663
  ```
664
 
665
  ``` bnf
666
  lambda-specifier:
667
  consteval
 
670
  static
671
  ```
672
 
673
  ``` bnf
674
  lambda-specifier-seq:
675
+ lambda-specifier lambda-specifier-seqₒₚₜ
 
676
  ```
677
 
678
  A *lambda-expression* provides a concise way to create a simple function
679
  object.
680
 
 
700
  *attribute-specifier-seq*, which collides with the
701
  *attribute-specifier-seq* in *lambda-expression*. In such cases, any
702
  attributes are treated as *attribute-specifier-seq* in
703
  *lambda-expression*.
704
 
705
+ [*Note 2*:
706
+
707
+ Such ambiguous cases cannot have valid semantics because the constraint
708
+ expression would not have type `bool`.
709
+
710
+ [*Example 2*:
711
+
712
+ ``` cpp
713
+ auto x = []<class T> requires T::operator int [[some_attribute]] (int) { }
714
+ ```
715
+
716
+ — *end example*]
717
+
718
+ — *end note*]
719
 
720
  A *lambda-specifier-seq* shall contain at most one of each
721
  *lambda-specifier* and shall not contain both `constexpr` and
722
  `consteval`. If the *lambda-declarator* contains an explicit object
723
  parameter [[dcl.fct]], then no *lambda-specifier* in the
 
727
  *lambda-capture*.
728
 
729
  [*Note 3*: The trailing *requires-clause* is described in
730
  [[dcl.decl]]. — *end note*]
731
 
732
+ A *lambda-expression*'s *parameter-declaration-clause* is the
733
+ *parameter-declaration-clause* of the *lambda-expression*'s
734
+ *lambda-declarator*, if any, or empty otherwise. If the
735
+ *lambda-declarator* does not include a *trailing-return-type*, it is
736
+ considered to be `-> auto`.
737
 
738
  [*Note 4*: In that case, the return type is deduced from `return`
739
  statements as described in [[dcl.spec.auto]]. — *end note*]
740
 
741
+ [*Example 3*:
742
 
743
  ``` cpp
744
  auto x1 = [](int i) { return i; }; // OK, return type is int
745
  auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from braced-init-list
746
  int j;
 
751
 
752
  A lambda is a *generic lambda* if the *lambda-expression* has any
753
  generic parameter type placeholders [[dcl.spec.auto]], or if the lambda
754
  has a *template-parameter-list*.
755
 
756
+ [*Example 4*:
757
 
758
  ``` cpp
759
+ auto x = [](int i, auto a) { return i; }; // OK, a generic lambda
760
+ auto y = [](this auto self, int i) { return i; }; // OK, a generic lambda
761
+ auto z = []<class T>(int i) { return i; }; // OK, a generic lambda
762
  ```
763
 
764
  — *end example*]
765
 
766
  #### Closure types <a id="expr.prim.lambda.closure">[[expr.prim.lambda.closure]]</a>
767
 
768
  The type of a *lambda-expression* (which is also the type of the closure
769
  object) is a unique, unnamed non-union class type, called the *closure
770
  type*, whose properties are described below.
771
 
772
+ The closure type is incomplete until the end of its corresponding
773
+ *compound-statement*.
774
+
775
  The closure type is declared in the smallest block scope, class scope,
776
  or namespace scope that contains the corresponding *lambda-expression*.
777
 
778
  [*Note 1*: This determines the set of namespaces and classes associated
779
  with the closure type [[basic.lookup.argdep]]. The parameter types of a
780
  *lambda-declarator* do not affect these associated namespaces and
781
  classes. — *end note*]
782
 
783
+ The closure type is not an aggregate type [[dcl.init.aggr]]; it is a
784
+ structural type [[term.structural.type]] if and only if the lambda has
785
+ no *lambda-capture*. An implementation may define the closure type
786
+ differently from what is described below provided this does not alter
787
+ the observable behavior of the program other than by changing:
788
 
789
  - the size and/or alignment of the closure type,
790
+ - whether the closure type is trivially copyable [[class.prop]],
791
+ - whether the closure type is trivially relocatable [[class.prop]],
792
+ - whether the closure type is replaceable [[class.prop]], or
793
  - whether the closure type is a standard-layout class [[class.prop]].
794
 
795
  An implementation shall not add members of rvalue reference type to the
796
  closure type.
797
 
798
  The closure type for a *lambda-expression* has a public inline function
799
  call operator (for a non-generic lambda) or function call operator
800
  template (for a generic lambda) [[over.call]] whose parameters and
801
+ return type are those of the *lambda-expression*'s
802
  *parameter-declaration-clause* and *trailing-return-type* respectively,
803
  and whose *template-parameter-list* consists of the specified
804
+ *template-parameter-list*, if any. The function call operator or the
805
+ function call operator template are direct members of the closure type.
806
+ The *requires-clause* of the function call operator template is the
807
+ *requires-clause* immediately following
808
  `<` *template-parameter-list* `>`, if any. The trailing
809
  *requires-clause* of the function call operator or operator template is
810
  the *requires-clause* of the *lambda-declarator*, if any.
811
 
812
  [*Note 2*: The function call operator template for a generic lambda can
 
843
  Given a lambda with a *lambda-capture*, the type of the explicit object
844
  parameter, if any, of the lambda’s function call operator (possibly
845
  instantiated from a function call operator template) shall be either:
846
 
847
  - the closure type,
848
+ - a class type publicly and unambiguously derived from the closure type,
849
+ or
850
  - a reference to a possibly cv-qualified such type.
851
 
852
  [*Example 2*:
853
 
854
  ``` cpp
 
872
  `static`. Otherwise, it is a non-static member function or member
873
  function template [[class.mfct.non.static]] that is declared `const`
874
  [[class.mfct.non.static]] if and only if the *lambda-expression*’s
875
  *parameter-declaration-clause* is not followed by `mutable` and the
876
  *lambda-declarator* does not contain an explicit object parameter. It is
877
+ neither virtual nor declared `volatile`. Any *noexcept-specifier* or
878
+ *function-contract-specifier* [[dcl.contract.func]] specified on a
879
+ *lambda-expression* applies to the corresponding function call operator
880
+ or operator template. An *attribute-specifier-seq* in a
881
  *lambda-declarator* appertains to the type of the corresponding function
882
  call operator or operator template. An *attribute-specifier-seq* in a
883
  *lambda-expression* preceding a *lambda-declarator* appertains to the
884
  corresponding function call operator or operator template. The function
885
  call operator or any given operator template specialization is a
 
958
 
959
  — *end example*]
960
 
961
  — *end note*]
962
 
963
+ If all potential references to a local entity implicitly captured by a
964
+ *lambda-expression* L occur within the function contract assertions
965
+ [[dcl.contract.func]] of the call operator or operator template of L or
966
+ within *assertion-statement*s [[stmt.contract.assert]] within the body
967
+ of L, the program is ill-formed.
968
+
969
+ [*Note 4*: Adding a contract assertion to an existing C++ program
970
+ cannot cause additional captures. — *end note*]
971
+
972
+ [*Example 6*:
973
+
974
+ ``` cpp
975
+ static int i = 0;
976
+
977
+ void test() {
978
+ auto f1 = [=] pre(i > 0) {}; // OK, no local entities are captured.
979
+
980
+ int i = 1;
981
+ auto f2 = [=] pre(i > 0) {}; // error: cannot implicitly capture i here
982
+ auto f3 = [i] pre(i > 0) {}; // OK, i is captured explicitly.
983
+
984
+ auto f4 = [=] {
985
+ contract_assert(i > 0); // error: cannot implicitly capture i here
986
+ };
987
+
988
+ auto f5 = [=] {
989
+ contract_assert(i > 0); // OK, i is referenced elsewhere.
990
+ (void)i;
991
+ };
992
+
993
+ auto f6 = [=] pre( // #1
994
+ []{
995
+ bool x = true;
996
+ return [=]{ return x; }(); // OK, #1 captures nothing.
997
+ }()) {};
998
+
999
+ bool y = true;
1000
+ auto f7 = [=] pre([=]{ return y; }()); // error: outer capture of y is invalid.
1001
+ }
1002
+ ```
1003
+
1004
+ — *end example*]
1005
+
1006
  The closure type for a non-generic *lambda-expression* with no
1007
+ *lambda-capture* and no explicit object parameter [[dcl.fct]] whose
1008
+ constraints (if any) are satisfied has a conversion function to pointer
1009
+ to function with C++ language linkage [[dcl.link]] having the same
1010
+ parameter and return types as the closure type’s function call operator.
1011
+ The conversion is to “pointer to `noexcept` function” if the function
1012
+ call operator has a non-throwing exception specification. If the
1013
+ function call operator is a static member function, then the value
1014
+ returned by this conversion function is a pointer to the function call
1015
+ operator. Otherwise, the value returned by this conversion function is a
1016
+ pointer to a function `F` that, when invoked, has the same effect as
1017
+ invoking the closure type’s function call operator on a
1018
+ default-constructed instance of the closure type. `F` is a constexpr
1019
+ function if the function call operator is a constexpr function and is an
1020
+ immediate function if the function call operator is an immediate
1021
+ function.
1022
 
1023
+ For a generic lambda with no *lambda-capture* and no explicit object
1024
+ parameter [[dcl.fct]], the closure type has a conversion function
1025
+ template to pointer to function. The conversion function template has
1026
+ the same invented template parameter list, and the pointer to function
1027
+ has the same parameter types, as the function call operator template.
1028
+ The return type of the pointer to function shall behave as if it were a
1029
+ *decltype-specifier* denoting the return type of the corresponding
1030
+ function call operator template specialization.
1031
 
1032
+ [*Note 5*:
1033
 
1034
  If the generic lambda has no *trailing-return-type* or the
1035
  *trailing-return-type* contains a placeholder type, return type
1036
  deduction of the corresponding function call operator template
1037
  specialization has to be done. The corresponding specialization is that
 
1063
  };
1064
  ```
1065
 
1066
  — *end note*]
1067
 
1068
+ [*Example 7*:
1069
 
1070
  ``` cpp
1071
  void f1(int (*)(int)) { }
1072
  void f2(char (*)(int)) { }
1073
 
 
1087
 
1088
  — *end example*]
1089
 
1090
  If the function call operator template is a static member function
1091
  template, then the value returned by any given specialization of this
1092
+ conversion function template is a pointer to the corresponding function
1093
+ call operator template specialization. Otherwise, the value returned by
1094
+ any given specialization of this conversion function template is a
1095
+ pointer to a function `F` that, when invoked, has the same effect as
1096
+ invoking the generic lambda’s corresponding function call operator
1097
+ template specialization on a default-constructed instance of the closure
1098
+ type. `F` is a constexpr function if the corresponding specialization is
1099
+ a constexpr function and `F` is an immediate function if the function
1100
+ call operator template specialization is an immediate function.
 
1101
 
1102
+ [*Note 6*: This will result in the implicit instantiation of the
1103
  generic lambda’s body. The instantiated generic lambda’s return type and
1104
+ parameter types need to match the return type and parameter types of the
1105
+ pointer to function. — *end note*]
1106
 
1107
+ [*Example 8*:
1108
 
1109
  ``` cpp
1110
  auto GL = [](auto a) { std::cout << a; return a; };
1111
  int (*GL_int)(int) = GL; // OK, through conversion function template
1112
  GL_int(3); // OK, same as GL(3)
 
1116
 
1117
  The conversion function or conversion function template is public,
1118
  constexpr, non-virtual, non-explicit, const, and has a non-throwing
1119
  exception specification [[except.spec]].
1120
 
1121
+ [*Example 9*:
1122
 
1123
  ``` cpp
1124
  auto Fwd = [](int (*fp)(int), auto a) { return fp(a); };
1125
  auto C = [](auto a) { return a; };
1126
 
 
1135
 
1136
  The *lambda-expression*’s *compound-statement* yields the
1137
  *function-body* [[dcl.fct.def]] of the function call operator, but it is
1138
  not within the scope of the closure type.
1139
 
1140
+ [*Example 10*:
1141
 
1142
  ``` cpp
1143
  struct S1 {
1144
  int x, y;
1145
  int operator()(int);
 
1152
  };
1153
  ```
1154
 
1155
  — *end example*]
1156
 
1157
+ Unless the *compound-statement* is that of a
1158
+ *consteval-block-declaration* [[dcl.pre]], a variable `__func__` is
1159
+ implicitly defined at the beginning of the *compound-statement* of the
1160
+ *lambda-expression*, with semantics as described in 
1161
+ [[dcl.fct.def.general]].
1162
 
1163
  The closure type associated with a *lambda-expression* has no default
1164
  constructor if the *lambda-expression* has a *lambda-capture* and a
1165
  defaulted default constructor otherwise. It has a defaulted copy
1166
  constructor and a defaulted move constructor [[class.copy.ctor]]. It has
1167
  a deleted copy assignment operator if the *lambda-expression* has a
1168
  *lambda-capture* and defaulted copy and move assignment operators
1169
  otherwise [[class.copy.assign]].
1170
 
1171
+ [*Note 7*: These special member functions are implicitly defined as
1172
  usual, which can result in them being defined as deleted. — *end note*]
1173
 
1174
  The closure type associated with a *lambda-expression* has an
1175
  implicitly-declared destructor [[class.dtor]].
1176
 
 
1208
  ``` bnf
1209
  simple-capture:
1210
  identifier '...'ₒₚₜ
1211
  '&' identifier '...'ₒₚₜ
1212
  this
1213
+ '*' this
1214
  ```
1215
 
1216
  ``` bnf
1217
  init-capture:
1218
  '...'ₒₚₜ identifier initializer
1219
  '&' '...'ₒₚₜ identifier initializer
1220
  ```
1221
 
1222
  The body of a *lambda-expression* may refer to local entities of
1223
+ enclosing scopes by capturing those entities, as described below.
1224
 
1225
  If a *lambda-capture* includes a *capture-default* that is `&`, no
1226
  identifier in a *simple-capture* of that *lambda-capture* shall be
1227
  preceded by `&`. If a *lambda-capture* includes a *capture-default* that
1228
  is `=`, each *simple-capture* of that *lambda-capture* shall be of the
1229
  form “`&` *identifier* `...`ₒₚₜ ”, “`this`”, or “`* this`”.
1230
 
1231
  [*Note 1*: The form `[&,this]` is redundant but accepted for
1232
+ compatibility with C++14. — *end note*]
1233
 
1234
  Ignoring appearances in *initializer*s of *init-capture*s, an identifier
1235
  or `this` shall not appear more than once in a *lambda-capture*.
1236
 
1237
  [*Example 1*:
 
1250
  ```
1251
 
1252
  — *end example*]
1253
 
1254
  A *lambda-expression* shall not have a *capture-default* or
1255
+ *simple-capture* in its *lambda-introducer* unless
1256
+
1257
+ - its innermost enclosing scope is a block scope [[basic.scope.block]],
1258
+ - it appears within a default member initializer and its innermost
1259
+ enclosing scope is the corresponding class scope
1260
+ [[basic.scope.class]], or
1261
+ - it appears within a contract assertion and its innermost enclosing
1262
+ scope is the corresponding contract-assertion scope
1263
+ [[basic.scope.contract]].
1264
 
1265
  The *identifier* in a *simple-capture* shall denote a local entity
1266
  [[basic.lookup.unqual]], [[basic.pre]]. The *simple-capture*s `this` and
1267
  `* this` denote the local entity `*this`. An entity that is designated
1268
  by a *simple-capture* is said to be *explicitly captured*.
 
1480
  An entity is *captured by copy* if
1481
 
1482
  - it is implicitly captured, the *capture-default* is `=`, and the
1483
  captured entity is not `*this`, or
1484
  - it is explicitly captured with a capture that is not of the form
1485
+ `this`, `&` *identifier* `...`ₒₚₜ , or `&` `...`ₒₚₜ *identifier*
1486
+ *initializer*.
1487
 
1488
  For each entity captured by copy, an unnamed non-static data member is
1489
  declared in the closure type. The declaration order of these members is
1490
  unspecified. The type of such a data member is the referenced type if
1491
  the entity is a reference to an object, an lvalue reference to the
 
1512
  ``` cpp
1513
  void f(const int*);
1514
  void g() {
1515
  const int N = 10;
1516
  [=] {
1517
+ int arr[N]; // OK, not an odr-use, refers to variable with automatic storage duration
1518
  f(&N); // OK, causes N to be captured; &N points to
1519
  // the corresponding member of the closure type
1520
  };
1521
  }
1522
  ```
 
1683
  }
1684
  ```
1685
 
1686
  — *end example*]
1687
 
1688
+ A fold expression is a pack expansion.
1689
+
1690
  ### Requires expressions <a id="expr.prim.req">[[expr.prim.req]]</a>
1691
 
1692
  #### General <a id="expr.prim.req.general">[[expr.prim.req.general]]</a>
1693
 
1694
  A *requires-expression* provides a concise way to express requirements
 
1710
  '{' requirement-seq '}'
1711
  ```
1712
 
1713
  ``` bnf
1714
  requirement-seq:
1715
+ requirement requirement-seqₒₚₜ
 
1716
  ```
1717
 
1718
  ``` bnf
1719
  requirement:
1720
  simple-requirement
 
1722
  compound-requirement
1723
  nested-requirement
1724
  ```
1725
 
1726
  A *requires-expression* is a prvalue of type `bool` whose value is
1727
+ described below.
 
1728
 
1729
  [*Example 1*:
1730
 
1731
  A common use of *requires-expression*s is to define requirements in
1732
  concepts such as the one below:
 
1753
  introduces the *requires-expression*.
1754
 
1755
  — *end example*]
1756
 
1757
  A *requires-expression* may introduce local parameters using a
1758
+ *parameter-declaration-clause*. A local parameter of a
1759
+ *requires-expression* shall not have a default argument. The type of
1760
+ such a parameter is determined as specified for a function parameter in 
1761
+ [[dcl.fct]]. These parameters have no linkage, storage, or lifetime;
1762
+ they are only used as notation for the purpose of defining
1763
+ *requirement*s. The *parameter-declaration-clause* of a
1764
+ *requirement-parameter-list* shall not terminate with an ellipsis.
1765
 
1766
  [*Example 2*:
1767
 
1768
  ``` cpp
1769
  template<typename T>
1770
  concept C = requires(T t, ...) { // error: terminates with an ellipsis
1771
  t;
1772
  };
1773
+ template<typename T>
1774
+ concept C2 = requires(T p[2]) {
1775
+ (decltype(p))nullptr; // OK, p has type ``pointer to T''
1776
+ };
1777
  ```
1778
 
1779
  — *end example*]
1780
 
1781
+ The substitution of template arguments into a *requires-expression* can
1782
+ result in the formation of invalid types or expressions in the immediate
1783
+ context of its *requirement*s [[temp.deduct.general]] or the violation
1784
+ of the semantic constraints of those *requirement*s. In such cases, the
1785
+ *requires-expression* evaluates to `false`; it does not cause the
1786
+ program to be ill-formed. The substitution and semantic constraint
1787
+ checking proceeds in lexical order and stops when a condition that
1788
+ determines the result of the *requires-expression* is encountered. If
1789
+ substitution (if any) and semantic constraint checking succeed, the
1790
+ *requires-expression* evaluates to `true`.
1791
 
1792
  [*Note 1*: If a *requires-expression* contains invalid types or
1793
  expressions in its *requirement*s, and it does not appear within the
1794
  declaration of a templated entity, then the program is
1795
  ill-formed. — *end note*]
 
1801
  [*Example 3*:
1802
 
1803
  ``` cpp
1804
  template<typename T> concept C =
1805
  requires {
1806
+ new decltype((void)T{}); // ill-formed, no diagnostic required
1807
  };
1808
  ```
1809
 
1810
  — *end example*]
1811
 
 
1814
  ``` bnf
1815
  simple-requirement:
1816
  expression ';'
1817
  ```
1818
 
1819
+ A *simple-requirement* asserts the validity of an *expression*. The
1820
+ *expression* is an unevaluated operand.
1821
 
1822
  [*Note 1*: The enclosing *requires-expression* will evaluate to `false`
1823
+ if substitution of template arguments into the *expression*
1824
+ fails. *end note*]
 
1825
 
1826
  [*Example 1*:
1827
 
1828
  ``` cpp
1829
  template<typename T> concept C =
 
1843
  #### Type requirements <a id="expr.prim.req.type">[[expr.prim.req.type]]</a>
1844
 
1845
  ``` bnf
1846
  type-requirement:
1847
  typename nested-name-specifierₒₚₜ type-name ';'
1848
+ typename splice-specifier
1849
+ typename splice-specialization-specifier
1850
  ```
1851
 
1852
+ A *type-requirement* asserts the validity of a type. The component names
1853
+ of a *type-requirement* are those of its *nested-name-specifier* (if
1854
+ any) and *type-name* (if any).
1855
 
1856
  [*Note 1*: The enclosing *requires-expression* will evaluate to `false`
1857
  if substitution of template arguments fails. — *end note*]
1858
 
1859
  [*Example 1*:
 
1862
  template<typename T, typename T::type = 0> struct S;
1863
  template<typename T> using Ref = T&;
1864
 
1865
  template<typename T> concept C = requires {
1866
  typename T::inner; // required nested member name
1867
+ typename S<T>; // required valid[temp.names] template-id; fails if T::type does not exist as a type
1868
+ // to which 0 can be implicitly converted
1869
  typename Ref<T>; // required alias template substitution, fails if T is void
1870
+ typename [:T::r1:]; // fails if T::r1 is not a reflection of a type
1871
+ typename [:T::r2:]<int>; // fails if T::r2 is not a reflection of a template Z for which Z<int> is a type
1872
  };
1873
  ```
1874
 
1875
  — *end example*]
1876
 
 
1887
  ``` bnf
1888
  return-type-requirement:
1889
  '->' type-constraint
1890
  ```
1891
 
1892
+ A *compound-requirement* asserts properties of the *expression* E. The
1893
+ *expression* is an unevaluated operand. Substitution of template
1894
+ arguments (if any) and verification of semantic properties proceed in
1895
+ the following order:
1896
 
1897
  - Substitution of template arguments (if any) into the *expression* is
1898
  performed.
1899
  - If the `noexcept` specifier is present, E shall not be a
1900
  potentially-throwing expression [[except.spec]].
 
1984
  `D<T>` is satisfied if `sizeof(decltype (+t)) == 1`
1985
  [[temp.constr.atomic]].
1986
 
1987
  — *end example*]
1988
 
1989
+ ### Expression splicing <a id="expr.prim.splice">[[expr.prim.splice]]</a>
1990
+
1991
+ ``` bnf
1992
+ splice-expression:
1993
+ splice-specifier
1994
+ template splice-specifier
1995
+ template splice-specialization-specifier
1996
+ ```
1997
+
1998
+ A *splice-specifier* or *splice-specialization-specifier* immediately
1999
+ followed by `::` or preceded by `typename` is never interpreted as part
2000
+ of a *splice-expression*.
2001
+
2002
+ [*Example 1*:
2003
+
2004
+ ``` cpp
2005
+ struct S { static constexpr int a = 1; };
2006
+ template<typename> struct TCls { static constexpr int b = 2; };
2007
+
2008
+ constexpr int c = [:^^S:]::a; // OK, [:^^ S:] is not an expression
2009
+ constexpr int d = template [:^^TCls:]<int>::b; // OK, template [:^^ TCls:]<int> is not an expression
2010
+ template<auto V> constexpr int e = [:V:]; // OK
2011
+ constexpr int f = template [:^^e:]<^^S::a>; // OK
2012
+
2013
+ constexpr auto g = typename [:^^int:](42); // OK, typename [:^^ int:] is a splice-type-specifier
2014
+
2015
+ constexpr auto h = ^^g;
2016
+ constexpr auto i = e<[:^^h:]>; // error: unparenthesized splice-expression used as template argument
2017
+ constexpr auto j = e<([:^^h:])>; // OK
2018
+ ```
2019
+
2020
+ — *end example*]
2021
+
2022
+ For a *splice-expression* of the form *splice-specifier*, let S be the
2023
+ construct designated by *splice-specifier*.
2024
+
2025
+ - The expression is ill-formed if S is
2026
+ - a constructor,
2027
+ - a destructor,
2028
+ - an unnamed bit-field, or
2029
+ - a local entity [[basic.pre]] such that
2030
+ - there is a lambda scope that intervenes between the expression and
2031
+ the point at which S was introduced and
2032
+ - the expression would be potentially evaluated if the effect of any
2033
+ enclosing `typeid` expressions [[expr.typeid]] were ignored.
2034
+ - Otherwise, if S is a function F, the expression denotes an overload
2035
+ set containing all declarations of F that precede either the
2036
+ expression or the point immediately following the *class-specifier* of
2037
+ the outermost class for which the expression is in a complete-class
2038
+ context; overload resolution is performed
2039
+ [[over.match]], [[over.over]].
2040
+ - Otherwise, if S is an object or a non-static data member, the
2041
+ expression is an lvalue designating S. The expression has the same
2042
+ type as that of S, and is a bit-field if and only if S is a bit-field.
2043
+ \[*Note 1*: The implicit transformation whereby an *id-expression*
2044
+ denoting a non-static member becomes a class member access
2045
+ [[expr.prim.id]] does not apply to a
2046
+ *splice-expression*. — *end note*]
2047
+ - Otherwise, if S is a variable or a structured binding, S shall either
2048
+ have static or thread storage duration or shall inhabit a scope
2049
+ enclosing the expression. The expression is an lvalue referring to the
2050
+ object or function X associated with or referenced by S, has the same
2051
+ type as that of S, and is a bit-field if and only if X is a bit-field.
2052
+ \[*Note 2*: The type of a *splice-expression* designating a variable
2053
+ or structured binding of reference type will be adjusted to a
2054
+ non-reference type [[expr.type]]. — *end note*]
2055
+ - Otherwise, if S is a value or an enumerator, the expression is a
2056
+ prvalue that computes S and whose type is the same as that of S.
2057
+ - Otherwise, the expression is ill-formed.
2058
+
2059
+ For a *splice-expression* of the form `template splice-specifier`, the
2060
+ *splice-specifier* shall designate a function template T that is not a
2061
+ constructor template. The expression denotes an overload set containing
2062
+ all declarations of T that precede either the expression or the point
2063
+ immediately following the *class-specifier* of the outermost class for
2064
+ which the expression is in a complete-class context; overload resolution
2065
+ is performed.
2066
+
2067
+ [*Note 3*: During overload resolution, candidate function templates
2068
+ undergo template argument deduction and the resulting specializations
2069
+ are considered as candidate functions. — *end note*]
2070
+
2071
+ For a *splice-expression* of the form
2072
+ `template splice-specialization-specifier`, the *splice-specifier* of
2073
+ the *splice-specialization-specifier* shall designate a template T.
2074
+
2075
+ - If T is a function template, the expression denotes an overload set
2076
+ containing all declarations of T that precede either the expression or
2077
+ the point immediately following the *class-specifier* of the outermost
2078
+ class for which the expression is in a complete-class context;
2079
+ overload resolution is performed [[over.match]], [[over.over]].
2080
+ - Otherwise, if T is a variable template, let S be the specialization of
2081
+ T corresponding to the template argument list of the
2082
+ *splice-specialization-specifier*. The expression is an lvalue
2083
+ referring to the object associated with S and has the same type as
2084
+ that of S.
2085
+ - Otherwise, the expression is ill-formed.
2086
+
2087
+ [*Note 4*: Class members are accessible from any point when designated
2088
+ by *splice-expression*s [[class.access.base]]. A class member access
2089
+ expression [[expr.ref]] whose right operand is a *splice-expression* is
2090
+ ill-formed if the left operand (considered as a pointer) cannot be
2091
+ implicitly converted to a pointer to the designating class of the right
2092
+ operand. — *end note*]
2093
+