Files
2025-10-25 03:02:53 +03:00

8.7 KiB
Raw Permalink Blame History

[expr.prim.splice]

7 Expressions [expr]

7.5 Primary expressions [expr.prim]

7.5.9 Expression splicing [expr.prim.splice]

splice-expression:
splice-specifier
template splice-specifier
template splice-specialization-specifier

1

#

A splice-specifier or splice-specialization-specifier immediately followed by :: or preceded by typename is never interpreted as part of a splice-expression.

[Example 1: struct S { static constexpr int a = 1; };template struct TCls { static constexpr int b = 2; };

constexpr int c = [:^^S:]::a; // OK, [:^^S:] is not an expressionconstexpr int d = template [:^^TCls:]::b; // OK, template [:^^TCls:] is not an expressiontemplate constexpr int e = [:V:]; // OKconstexpr int f = template [:^^e:]<^^S::a>; // OKconstexpr auto g = typename :^^int:; // OK, typename [:^^int:] is a splice-type-specifierconstexpr auto h = ^^g;constexpr auto i = e<[:^^h:]>; // error: unparenthesized splice-expression used as template argumentconstexpr auto j = e<([:^^h:])>; // OK — end example]

2

#

For a splice-expression of the form splice-specifier, let S be the construct designated by splice-specifier.

a constructor,

a destructor,

an unnamed bit-field, or

a local entity ([basic.pre]) such that + (2.1.4.1) there is a lambda scope that intervenes between the expression and the point at which S was introduced and

+
      [(2.1.4.2)](#2.1.4.2)

the expression would be potentially evaluated if the effect of any enclosing typeid expressions ([expr.typeid]) were ignored.

  • (2.2)

    Otherwise, if S is a function F, the expression denotes an overload set containing all declarations of F that precede either the expression or the point immediately following the class-specifier of the outermost class for which the expression is in a complete-class context; overload resolution is performed ([over.match], [over.over]).

  • (2.3)

    Otherwise, if S is an object or a non-static data member, the expression is an lvalue designating S. The expression has the same type as that of S, and is a bit-field if and only if S is a bit-field. [Note 1: The implicit transformation whereby an id-expression denoting a non-static member becomes a class member access ([expr.prim.id]) does not apply to a splice-expression. — end note]

  • (2.4)

    Otherwise, if S is a variable or a structured binding,S shall either have static or thread storage duration or shall inhabit a scope enclosing the expression. The expression is an lvalue referring to the object or function X associated with or referenced by S, has the same type as that of S, and is a bit-field if and only if X is a bit-field. [Note 2: The type of a splice-expression designating a variable or structured binding of reference type will be adjusted to a non-reference type ([expr.type]). — end note]

  • (2.5)

    Otherwise, if S is a value or an enumerator, the expression is a prvalue that computes S and whose type is the same as that of S.

  • (2.6)

    Otherwise, the expression is ill-formed.

3

#

For a splice-expression of the form template splice-specifier, the splice-specifier shall designate a function template T that is not a constructor template.

The expression denotes an overload set containing all declarations of T that precede either the expression or the point immediately following the class-specifier of the outermost class for which the expression is in a complete-class context; overload resolution is performed.

[Note 3:

During overload resolution, candidate function templates undergo template argument deduction and the resulting specializations are considered as candidate functions.

— end note]

4

#

For a splice-expression of the form template splice-specialization-specifier, the splice-specifier of the splice-specialization-specifier shall designate a template T.

  • (4.1)

    If T is a function template, the expression denotes an overload set containing all declarations of T that precede either the expression or the point immediately following the class-specifier of the outermost class for which the expression is in a complete-class context; overload resolution is performed ([over.match], [over.over]).

  • (4.2)

    Otherwise, if T is a variable template, let S be the specialization of T corresponding to the template argument list of the splice-specialization-specifier. The expression is an lvalue referring to the object associated with S and has the same type as that of S.

  • (4.3)

    Otherwise, the expression is ill-formed.

[Note 4:

Class members are accessible from any point when designated by splice-expressions ([class.access.base]).

A class member access expression ([expr.ref]) whose right operand is a splice-expression is ill-formed if the left operand (considered as a pointer) cannot be implicitly converted to a pointer to the designating class of the right operand.

— end note]