foo > 0.0F
is not a core constant expression:
- An expression e is a core constant expression unless the evaluation of e, following the rules of the abstract machine, would evaluate one
of the following expressions:
...
(2.7) an lvalue-to-rvalue conversion unless it is applied to
(2.7.1) a non-volatile glvalue of integral or enumeration type that
refers to a complete non-volatile const object with a preceding
initialization, initialized with a constant expression, or
(2.7.2) a non-volatile glvalue that refers to a subobject of a string
literal, or
(2.7.3) a non-volatile glvalue that refers to a non-volatile object
defined with constexpr, or that refers to a non-mutable subobject of
such an object, or
(2.7.4) a non-volatile glvalue of literal type that refers to a
non-volatile object whose lifetime began within the evaluation of e;
foo
is of floating-point type, for foo > 0.0F
an lvalue-to-rvalue conversion on foo
is required, which doesn't match the above conditions, then foo > 0.0F
is not considered as constant expression:
A constant expression is either a glvalue core constant expression that refers to an entity that is a permitted result of a constant expression (as defined below), or a prvalue core constant expression whose value satisfies the following constraints
On the other hand, if declare foo
as integral type the code would be fine. LIVE (Usingconstexpr
instead of const
works too. LIVE)