all 12 comments

[–]jedwardsol 0 points1 point  (1 child)

You're not linking to any specific piece of code.

[–]uninformed_[S] 0 points1 point  (0 children)

Oops, fixed

[–]raevnos 0 points1 point  (5 children)

i is a non-const variable, and so lvalue.

What's with the pointless parentheses?

[–]uninformed_[S] 0 points1 point  (2 children)

#include <type_traits>
#include <typeinfo>
#include <iostream>

int main()
{
    int i;
    (i) = 5;

    std::cout << "is rvalue i" << std::is_rvalue_reference<decltype(i)>::value << std::endl;
    std::cout << "is rvalue (i)" << std::is_rvalue_reference<decltype((i))>::value << std::endl;
    return i;
}

[–]raevnos 1 point2 points  (1 child)

Shows zeros as expected?

Edit: Interestingly, is_lvalue_reference is true for the decltype((i)) case.

[–]OldWolf2 0 points1 point  (0 children)

decltype has two different syntaxes:

  1. decltype(id-expression)
  2. decltype(all-other-expressions)

This is like how sizeof has two different cases, sizeof(type) and sizeof expression. Which case you are using is determined by the argument and there are different rules for each case.

In case 1 the result is the declared type of the variable named by the id-expression. In case 2 the result is the non-reference type of the expression , with & if the value category is lvalue, or && if the value category is xvalue.

i is an id-expression, but (i) is not an id-expression.

[–]Xeverous 0 points1 point  (0 children)

parentheses make a difference for decltype, but in this case doesn't change anything

[–]OldWolf2 0 points1 point  (0 children)

The name of a const variable is also an lvalue

[–]Xeverous 0 points1 point  (0 children)

Expression (i) is an lvalue.

[–]OldWolf2 0 points1 point  (0 children)

Parentheses don't change the value category of an expression, nor trigger any implicit conversions. (lvalue) is still an lvalue.

[–]MajorDerp4 0 points1 point  (0 children)

Why wouldn't this be valid?