public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106520] New: 2+ index expressions in build_op_subscript are incorrectly interpreted as comma expression
@ 2022-08-03 22:29 mkretz at gcc dot gnu.org
2022-08-05 20:31 ` [Bug c++/106520] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: mkretz at gcc dot gnu.org @ 2022-08-03 22:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106520
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:
<source>: In function 'void f(A, B)':
<source>:15:4: warning: top-level comma expression in array subscript changed
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" function
gets called.
I'm not sure the compatibility issue is worth it. I think it would be better to
call build_op_subscript with unmodified complain and let code that turns on
-std=c++23 break if it relies on comma expressions in subscripts.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-05 20:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03 22:29 [Bug c++/106520] New: 2+ index expressions in build_op_subscript are incorrectly interpreted as comma expression mkretz at gcc dot gnu.org
2022-08-05 20:31 ` [Bug c++/106520] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).