Is (int &&) 5 an integral constant expression?

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 an integral or non-enumerated type of enumeration implicitly converted to prvalue, where the converted expression is an expression of a constant constant. [Note: such expressions can be used as array boundaries [...]

I'm not sure, because the expression looks like a type int&&, but the definition of an integral type in 3.9 does not mention reference types.

If unclear, my question is: is there an static_cast<int&&>(5)integral constant expression?


Background: The question is motivated by the following example:

char *c = (1 - 1);
char *d = static_cast<int&&>(0);

g++ -std=c++11 c, d. ++ 11 , 0. ( ++ 14).

clang (3.4.1 ) c -std=c++11.

, , g++ , , b d.

+4
1

, static_cast<int&&>(5) , x ++ 11 5.2.9 [expr.static.cast]:

[...], T - r , xvalue [...]

5.19 [expr.const], :

, [...]

:

  • lvalue-to-rvalue (4.1),

:

  • glvalue literal, , , ;

:

clang (3.4.1 ) c -std = ++ 11.

T.C. DR 903, clangs .

+2

Source: https://habr.com/ru/post/1617681/


All Articles