Bug 85867 - Subscript operator applied to an temporary array results in an lvalue
Summary: Subscript operator applied to an temporary array results in an lvalue
Status: RESOLVED DUPLICATE of bug 79832
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
: 86187 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-05-22 04:27 UTC by Shafik Yaghmour
Modified: 2018-06-17 05:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shafik Yaghmour 2018-05-22 04:27:08 UTC
This Stackoverflow question https://stackoverflow.com/q/33161003/1708801 provides the following code:

using Y = int[10];

int main() {
    (Y { })[0] = 1;
}

which compiles without diagnostic, CWG defect report 1213: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1213 says the result of the  subscript operator should be an xvalue and therefore not assignable to.

Also see the following clang bug report on the same issue, which was resolved at the end of 2017: https://bugs.llvm.org/show_bug.cgi?id=25357

I have a godbolt for it here: https://godbolt.org/g/AmzbFh 

We can see that clang no longer allows this but gcc does.
Comment 1 Jonathan Wakely 2018-05-22 08:14:38 UTC
I'm pretty sure this is a dup of an existing bug.
Comment 2 Jonathan Wakely 2018-05-22 14:14:28 UTC
.

*** This bug has been marked as a duplicate of bug 79832 ***
Comment 3 Marc Glisse 2018-06-17 05:28:11 UTC
*** Bug 86187 has been marked as a duplicate of this bug. ***