Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the words "undefined" mean in bullet point §5.19/2.3 in N4140?

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.

like image 924
Belloc Avatar asked Mar 18 '23 12:03

Belloc


1 Answers

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.

like image 143
Shafik Yaghmour Avatar answered Apr 27 '23 07:04

Shafik Yaghmour