The
constexpr specifier shall be applied only to
the definition of a variable or variable template 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
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
. [
Note 1:
An explicit specialization can differ from the template declaration
with respect to the
constexpr or
consteval specifier
. —
end note]
[
Note 2:
Function parameters cannot be declared
constexpr. —
end note]
[
Example 1:
constexpr void square(int &x);
constexpr int bufsz = 1024;
constexpr struct pixel {
int x;
int y;
constexpr pixel(int);
};
constexpr pixel::pixel(int a)
: x(a), y(x)
{ square(x); }
constexpr pixel small(2);
constexpr void square(int &x) {
x *= x;
}
constexpr pixel large(4);
int next(constexpr int x) {
return x + 1;
}
extern constexpr int memsz;
—
end example]