public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mkretz at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-106520-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2022-08-03 22:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-03 22:29 mkretz at gcc dot gnu.org [this message]
2022-08-05 20:31 ` [Bug c++/106520] " pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-106520-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).