constexpr if and static_assert

前端 未结 4 2088
清酒与你
清酒与你 2020-11-27 06:39

P0292R1 constexpr if has been included, on track for C++17. It seems useful (and can replace use of SFINAE), but a comment regarding static_assert being ill

4条回答
  •  无人及你
    2020-11-27 07:13

    This is talking about a well-established rule for templates - the same rule that allows compilers to diagnose template void f() { return 1; }. [temp.res]/8 with the new change bolded:

    The program is ill-formed, no diagnostic required, if:

    • no valid specialization can be generated for a template or a substatement of a constexpr if statement ([stmt.if]) within a template and the template is not instantiated, or
    • [...]

    No valid specialization can be generated for a template containing static_assert whose condition is nondependent and evaluates to false, so the program is ill-formed NDR.

    static_asserts with a dependent condition that can evaluate to true for at least one type are not affected.

提交回复
热议问题