1

In such case:

int x=0;
(x)=5;

Why is (x) a valid lvalue (and decltype((x)) gives int&)? What do parentheses mean here? Is there any similar situation?

user
  • 475
  • 3
  • 10

1 Answers1

1

decltype(x) inspects the type of x entity. But when you put x inside parentheses, decltype have rules for deducing types for these expressions:

  • if the value category of expression is xvalue, then decltype yields T&&;
  • if the value category of expression is lvalue, then decltype yields T&;
  • if the value category of expression is prvalue, then decltype yields T.

source.

João Paulo
  • 6,300
  • 4
  • 51
  • 80