[Bug c++/85867] New: Subscript operator applied to an temporary array results in an lvalue

yaghmour.shafik at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue May 22 04:27:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85867

            Bug ID: 85867
           Summary: Subscript operator applied to an temporary array
                    results in an lvalue
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yaghmour.shafik at gmail dot com
  Target Milestone: ---

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.


More information about the Gcc-bugs mailing list