Open Quuxplusone opened 3 years ago
I also believe the following code should be accepted
constexpr char const array[] = "a";
static_assert(+array != "a");
The text at http://eel.is/c++draft/lex.string#9 says: "Evaluating a string-literal results in a string literal object with static storage duration ([basic.stc]). Whether all string-literals are distinct (that is, are stored in nonoverlapping objects) and whether successive evaluations of a string-literal yield the same or a different object is unspecified."
This text does not apply here (array
is not a string literal), so this comparison is also not unspecified.
The following well-formed translation unit
is rejected by clang with the error message
From the standard:
"An expression E is a core constant expression unless the evaluation of E, following the rules of the abstract machine ([intro.execution]), would evaluate one of the following: ... a three-way comparison ([expr.spaceship]), relational ([expr.rel]), or equality ([expr.eq]) operator where the result is unspecified;" (http://eel.is/c++draft/expr.const#5.23)
And:
If at least one of the operands is a pointer, pointer conversions, function pointer conversions, and qualification conversions are performed on both operands to bring them to their composite pointer type. Comparing pointers is defined as follows:
(http://eel.is/c++draft/expr.eq#3)
The unspecified condition does not apply, so this should be accepted.
See it live: https://godbolt.org/z/vrWh54KM1