The constexpr specifier shall be applied only to
the definition of a variable or variable template,
a structured binding declaration, or
the declaration of a function or function template.
The consteval specifier shall be applied only to
the declaration of a function or function template.
A function or static data member
declared with the constexpr or consteval specifier
on its first declaration
is implicitly an inline function or variable ([dcl.inline]).
If any declaration of a function or function template has
a constexpr or consteval specifier,
then all its declarations shall contain the same specifier.
An invocation of a constexpr function in a given context
produces the same result as
an invocation of an equivalent non-constexpr function in the same context
in all respects except that
The constexpr and consteval specifiers have no
effect on the type of a constexpr function.
[Example 3: constexprint bar(int x, int y)/ OK{return x + y + x*y; }/ ...int bar(int x, int y)/ error: redefinition of bar{return x *2+3* y; } — end example]
A constexpr specifier used in an object declaration
declares the object as const.
Such an object
shall have literal type and
shall be initialized.
A constexpr variable shall be constant-initializable ([expr.const]).
A constexpr variable that is an object,
as well as any temporary to which a constexpr reference is bound,
shall have constant destruction.
[Example 4: struct pixel {int x, y;
};
constexpr pixel ur ={1294, 1024}; / OKconstexpr pixel origin; / error: initializer missingnamespace N {void f(){int x;
constexprint& ar = x; / OKstaticconstexprint& sr = x; / error: x is not constexpr-representable/ at the point indicated below}/ immediate scope here is that of N} — end example]