From N4140 §5.19/2.3 (emphasis mine)
— an invocation of an undefined constexpr function or an undefined constexpr constructor;
From §7.1.5/2 constexpr functions and constructors are implicitly inlined, that is, if a constexpr function is not defined in a TU the code will just not compile.
This bullet was added by defect report 699 and it requires that a constexpr function or constructor must be defined before use. The defect report added the following example to 7.1.5
to demonstrate the rule:
constexpr int square(int x); //OK, declaration
constexpr struct pixel { // error: pixel is a type
int x;
int y;
constexpr pixel(int); // OK, declaration
};
constexpr pixel::pixel(int a)
: x(square(a)), y(square(a)) { } //OK, definition
constexpr pixel small(2); // error: square not defined, so small(2)
// not constant (5.19 [expr.const]), so constexpr not satisfied
constexpr int square(int x) { // OK, definition
return x * x;
}
constexpr pixel large(4); // OK, square defined
Note, the wording from this report changed with defect report 1365 to the wording currently in the draft standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With