You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""
If an expression of literal class type is used in a context where an integral constant expression is required, then that expression is contextually implicitly converted (Clause 7) to an integral or unscoped enumeration type and the selected conversion function shall be constexpr. [ Example:
struct A {
constexpr A(int i) : val(i) { }
constexpr operator int() const { return val; }
constexpr operator long() const { return 43; }
private:
int val;
};
template<int> struct X { };
constexpr A a = 42;
X<a> x; // OK: unique conversion to int
int ary[a]; // error: ambiguous conversion
— end example ]
"""
This example appears to be unrelated to the rule in question.
In X<a>, a is implicitly converted to int, and the rule does not apply.
In int ary[a], a is implicitly converted to size_t, and the rule does not apply.
Neither case is a context in which an integral constant expression is required; those are alignas(E) and bit-widths for bit-fields (and now also the implicit std::tuple_size<T>::value in structured bindings). We should probably use one of those in this example instead.
The text was updated successfully, but these errors were encountered:
"If an expression of literal class type is used in a context where an integral constant expression is required," only applies to bit-field widths and alignas anyway, so restrict appropriately (not in this editorial issue)
[expr.const]p7 says:
"""
If an expression of literal class type is used in a context where an integral constant expression is required, then that expression is contextually implicitly converted (Clause 7) to an integral or unscoped enumeration type and the selected conversion function shall be constexpr. [ Example:
— end example ]
"""
This example appears to be unrelated to the rule in question.
In
X<a>
,a
is implicitly converted toint
, and the rule does not apply.In
int ary[a]
,a
is implicitly converted tosize_t
, and the rule does not apply.Neither case is a context in which an integral constant expression is required; those are
alignas(E)
and bit-widths for bit-fields (and now also the implicitstd::tuple_size<T>::value
in structured bindings). We should probably use one of those in this example instead.The text was updated successfully, but these errors were encountered: