From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2D4F93858C39; Wed, 3 Aug 2022 22:29:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D4F93858C39 From: "mkretz at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106520] New: 2+ index expressions in build_op_subscript are incorrectly interpreted as comma expression Date: Wed, 03 Aug 2022 22:29:15 +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: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mkretz at gcc dot gnu.org 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 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: Wed, 03 Aug 2022 22:29:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106520 Bug ID: 106520 Summary: 2+ index expressions in build_op_subscript are incorrectly interpreted as comma expression Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mkretz at gcc dot gnu.org Target Milestone: --- Commit b38c9cf6d570f6c4c1109e00c8b81d82d0f24df3 implemented Multidimensional subscript operator [PR102611]. However, the backwards compatibility leads to surprising results. E.g.: struct A { void operator[](unsigned); void operator[](unsigned, unsigned); }; struct B { explicit operator unsigned() const; }; void f(A a, B b) { a[1]; a[b, 2]; } Compiles to two calls to A::operator[](unsigned) with the following diagnostics: : In function 'void f(A, B)': :15:4: warning: top-level comma expression in array subscript chang= ed meaning in C++23 [-Wcomma-subscript] 15 | a[b, 2]; | ^ [https://godbolt.org/z/f6vf3x5Gv] The user probably intended to call the two-index subscript overload. But there's no indication why the call failed. The warning is probably puzzling= to most users. It's probably not obvious to most users that the "wrong" functi= on gets called. I'm not sure the compatibility issue is worth it. I think it would be bette= r to call build_op_subscript with unmodified complain and let code that turns on -std=3Dc++23 break if it relies on comma expressions in subscripts.=