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

            Bug ID: 106775
           Summary: [11/12 regression] Subscipt operator with array rvalue
                    inside brackets returns lvalue
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: leduyquang753 at gmail dot com
  Target Milestone: ---

Created attachment 53519
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53519&action=edit
The command-line invocation of GCC, its verbose output and the preprocessed
source.

Using the built-in subscript operator with an array rvalue to the left (outside
brackets) and an integer to the right (inside brackets) returns an xvalue as
expected:

    test.cpp:10:21: error: using rvalue as lvalue [-fpremissive]
       10 |     getAnA().b[0] = 1;
          |     ~~~~~~~~~~~~^

But reversing the two operands makes GCC give an lvalue:

    0[getAnA().b] = 1;

No diagnostic with -Wall -Wextra -pedantic.

(Full preprocessed code attached.)

Test compiled using GCC 12.2.0 on Arch Linux and additionally on Windows and
Compiler explorer. Previous versions of GCC were tested on Compiler explorer
using x86-64 arch.

Other notes: MSVC in Visual studio 2022 seems to have the same issue while
Clang 14 doesn't.

Reply via email to