an object whose lifetime begins and ends
during the evaluation of a core constant expression.
[Example 1: constevalint plus1(int x){return x +1; }template<auto V>struct C {};
auto a = plus1; // error: immediate object not associated with constexpr variableconstexprauto b = plus1; // OKauto c = C<plus1>(); // OKauto d =^^int; // error: immediate object not associated with constexpr variableauto e = C<^^char>(); // OK — end example]
Each expression E that odr-uses a variable
that declares or refers to an immediate object
shall be in an immediate function context;
a diagnostic is required only if either
A glvalue core constant expression
that either refers to or points to an unspecified object
is not a constant expression.
— end note]
[Example 2: constevalint f(){return42; }constevalauto g(){return f; }constevalint h(int(*p)()= g()){return p(); }constexprint r = h(); // OKconstexprauto e = g(); // error: a pointer to an immediate function is// not a permitted result of a constant expressionstruct S {int x;
constexpr S(){}};
int i(){constexpr S s; // error: s.x has erroneous value} — end example]
An integral constant expression
is an expression of integral or
unscoped enumeration type, implicitly converted to a prvalue, where the converted expression is a core constant expression.
Such expressions can be
used as bit-field lengths ([class.bit]), as enumerator
initializers if the underlying type is not fixed ([dcl.enum]),
and as alignments.
If an expression of literal class type is used in a context where an
integral constant expression is required, then that expression is
contextually implicitly converted ([conv]) to an integral or unscoped
enumeration type
and the selected conversion function shall be constexpr.
[Example 3: struct A {constexpr A(int i): val(i){}constexproperatorint()const{return val; }constexproperatorlong()const{return42; }private:int val;
};
constexpr A a =alignof(int);
alignas(a)int n; // error: ambiguous conversionstruct B {int n : a; }; // error: ambiguous conversion — end example]
A converted constant expression
of type T is an
expression, implicitly converted to type T, where
the converted expression is a constant expression and the
implicit conversion sequence contains only