違反である (ill-formed) と考えます。
C++20 の項目で言えば 9.2.5.6 にある
For a constexpr function or constexpr constructor that is neither defaulted nor a template, if no argument values exist such that an invocation of the function or constructor could be an evaluated subexpression of a core constant expression, or, for a constructor, an evaluated subexpression of the initialization full-expression of some constant-initialized object, the program is ill-formed, no diagnostic required.
に引っかかります。
constexpr
関数はどんな入力に対しても定数を生成することがあり得ないような関数であってはならないというように読めます。 定数式が要求される文脈で関数が呼ばれるかどうかに関係なく constexpr
関数の定義に対する制限として記述されています。
また 16.5.5.7 では規格が constexpr
であることを要求している以外のライブラリ関数が constexpr
関数として宣言されてはならないというような文言もあるので std::strtof
が constexpr
関数であることはあり得ません。 故に質問の事例では constepxr
関数に対する要求を満たしていないと解釈できます。
ただ、診断不要 (no diagnostic required) とも書いてあるのでコンパイルが通る挙動が仕様に反しているというわけではないとも思います。
0 コメント