What do the words "undefined" in paragraph 5.5.19 / 2.3 of the bullet point in the N4140 mean?

From N4140 §5.19 / 2.3 (emphasis mine)

- function call undefined constexpr or undefined constructor constexpr;

From § 7.1.5 / 2, the constrespr functions and constructors are implicitly nested, i.e. if the constexpr function is not defined in TU, the code simply will not compile.

+4
source share
1 answer

​​ 699 , constexpr . 7.1.5, :

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

: 1365 , .

+7

Source: https://habr.com/ru/post/1569301/


All Articles