g++ accepts the code:
char b[static_cast<int&&>(5)];
N3936 [expr.const]/3 defines the term as:
An integral constant expression is an expression of integral or unscoped enumeration type, implicitly converted to a prvalue, where the converted expression is a core constant expression. [Note: Such expressions may be used as array bounds [...]
I'm unsure because the expression has type int&&
but the definition of integral type in 3.9 doesn't make any mention of reference types.
In case it was unclear, my question is: Is static_cast<int&&>(5)
an integral constant expression?
Background: The question is motivated by the following example:
char *c = (1 - 1);
char *d = static_cast<int&&>(0);
All recent versions of g++
with -std=c++11
accept the c
line but reject the d
line. The C++11 standard said that a null pointer constant is an integral constant expression with value 0
. (This was changed for C++14).
clang (3.4.1 and later) incorrectly rejects the c
line in -std=c++11
mode.
So it appears there is a bug in g++, but I'd like to confirm whether the bug is in the b
or the d
definition.
Aucun commentaire:
Enregistrer un commentaire