Consider the following code:
struct A {
constexpr operator int() { return 42; }
};
template
void foo() {}
void bar(A a) {
foo(
The user-defined conversion is allowed by [expr.const]/(4.1), and I don't see a single applicable bullet point in [expr.const]/2 that would prevent your expression from being a constant one. In fact, the requirements are so loose that declaring a
as
A a;
is still giving a well-formed program, even if a
didn't have a constexpr
default constructor etc., since the conversion operator is constexpr
and no members are evaluated.
As you saw yourself, GCC is contradictory in that it allows a
in the static_assert
condition but not a template-argument.