According to the standard a built-in subscript expression, where one operand is an array rvalue, is a xvalue (https://en.cppreference.com/w/cpp/language/value_category). But when I wrote a simple test I found out that MSVC considers such expressions as lvalue!
The following code fragment successfully compiles with MSVC:
using T5ElemArray = int[5];
&T5ElemArray{ 1, 2, 3, 4, 5 } [3] ;
T5ElemArray{ 1, 2, 3, 4, 5 } [3] = 77;
int& i = T5ElemArray{ 1, 2, 3, 4, 5 } [3] ;
Clang and g++ finds all three errors in the above code. Does anybody know anything about this bug?
This is CWG1213 which msvc hasn't implemented yet. MSVC compiles the invalid program even with
/permissive-flag.From expr.sub#2:
(emphasis mine)
The above means that we're not allowed to assign to the expression
T5ElemArray{ 1, 2, 3, 4, 5 } [3]or take its address using&.Here is the newly submitted msvc bug:
MSVC compiles assignment to result of substripting an rvalue array