From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A78AB3858C27; Thu, 11 Nov 2021 08:38:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A78AB3858C27 From: "de34 at live dot cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103183] New: ind[arr] produces an lvalue when arr is an array xvalue Date: Thu, 11 Nov 2021 08:38:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: accepts-invalid, rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: de34 at live dot cn X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Nov 2021 08:38:25 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103183 Bug ID: 103183 Summary: ind[arr] produces an lvalue when arr is an array xvalue Product: gcc Version: 10.1.0 Status: UNCONFIRMED Keywords: accepts-invalid, rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: de34 at live dot cn Target Milestone: --- With gcc 10 and later versions, the following program compiles in C++11/14 modes, but fails to compile in C++17 and later modes. It compiles in C++17 = and later modes if "int&&" is replaced with "int&" (which is wrong according to [expr.sub]/2). #include #include int main() { int arr[]{0}; static_assert(std::is_same::value, = ""); } It seems that arr[ind] doesn't suffer from this bug. Gcc 9 correctly produced an xvalue in this case. wandbox links (rejected valid code): gcc 12.0 (-std=3Dc++17): https://wandbox.org/permlink/HvNaq9T4J7oeYflt gcc 12.0 (-std=3Dc++14): https://wandbox.org/permlink/S3dhGvKr3aD5OeOW gcc 10.1 (-std=3Dc++17): https://wandbox.org/permlink/NzqYCtytSUW4oZjR gcc 10.1 (-std=3Dc++14): https://wandbox.org/permlink/LviIophRujplHx6o gcc 9.3 (-std=3Dc++17): https://wandbox.org/permlink/JkCQHBdc3xqDSG9s wandbox links (accepted invalid code, with "int&&" replaced with "int&"): gcc 12.0 (-std=3Dc++17): https://wandbox.org/permlink/JkCQHBdc3xqDSG9s gcc 10.1 (-std=3Dc++17): https://wandbox.org/permlink/Yr3Vl2mbeDzGi02v=