Rvalue references in conditional expression

typedef decltype(true ? (long&&)0 : (long&&)0) T;

What should be T?

According to gcc (4.7), it long. According to clang (torso), this long&&. This difference causes clang not to compile code that uses gcc 4.7 libstdc ++. Who is right?

UPDATE . As ildjarn points out , Clang is right, and as Richard Smith points out, the libstdC ++ error is caused by the error in the Standard. Here is the corresponding GCC bug and the corresponding bug report .

+3
source share
1 answer

Klang is right. N3337 §7.1.6.2 / 4:

The type designated decltype(e)is defined as follows:

  • if e - id- unparenthesized , decltype(e) - e. e , ;
  • , e - x, decltype(e) - T&&, T - e;
  • , e lvalue, decltype(e) T&, T e;
  • decltype(e) e.

decltype .

§ 5/6:

[: x, :

  • , , rvalue ,
  • rvalue ,
  • , , x,
  • a .* "--", x, .

, , rvalue lvalues, rvalue xvalues; rvalue lvalues, . -end note]

, 0 - , §3.9/8 :

- (, cv-) , , , void.

– §5.16/4:

glvalues ​​ , , -, , .

(xvalue), x - gl.

+5

All Articles