在N4140的子弹点§5.19/ 2.3中,"未定义"是什么意思?

Bel*_*loc 4 c++ language-lawyer constant-expression constexpr c++14

N4140§5.19/2.3(强调我的)

- 调用未定义的 constexpr函数或 未定义的 constexpr构造函数;

从§7.1.5/ 2开始,constexpr函数和构造函数是隐式内联的,也就是说,如果未在TU中定义constexpr函数,则代码将无法编译.

Sha*_*our 7

该子弹是由缺陷报告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
Run Code Online (Sandbox Code Playgroud)

请注意,本报告中的措辞随着缺陷报告1365的变化而变为标准草案中的措辞.