public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7598] c++: allow variadic operator[] for C++23 [PR103460]
Date: Thu, 10 Mar 2022 14:28:55 +0000 (GMT)	[thread overview]
Message-ID: <20220310142855.90CAC3857813@sourceware.org> (raw)

https://gcc.gnu.org/g:e46843ff75c37c705811e0c13bb469eda13b5f6c

commit r12-7598-ge46843ff75c37c705811e0c13bb469eda13b5f6c
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 10 15:28:20 2022 +0100

    c++: allow variadic operator[] for C++23 [PR103460]
    
    wg21.link/p2128 removed "with exactly one parameter" from over.sub
    section.  grok_op_properties has for that the last 2 lines in:
        case OVL_OP_FLAG_BINARY:
          if (arity != 2)
            {
              if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
                break;
    but unfortunately it isn't enough, we reject variadic operator[]
    earlier.  The following patch accepts variadic operator[] for C++23
    too.
    
    2022-03-10  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/103460
            * decl.cc (grok_op_properties): Allow variadic operator[] for
            C++23.
    
            * g++.dg/cpp23/subscript7.C: New test.

Diff:
---
 gcc/cp/decl.cc                          |  6 +++++-
 gcc/testsuite/g++.dg/cpp23/subscript7.C | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 58210905ee9..37d52d8f804 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -15214,6 +15214,9 @@ grok_op_properties (tree decl, bool complain)
       if (!arg)
 	{
 	  /* Variadic.  */
+	  if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
+	    break;
+
 	  error_at (loc, "%qD must not have variable number of arguments",
 		    decl);
 	  return false;
@@ -15289,7 +15292,8 @@ grok_op_properties (tree decl, bool complain)
     }
 
   /* There can be no default arguments.  */
-  for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
+  for (tree arg = argtypes; arg && arg != void_list_node;
+       arg = TREE_CHAIN (arg))
     if (TREE_PURPOSE (arg))
       {
 	TREE_PURPOSE (arg) = NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/cpp23/subscript7.C b/gcc/testsuite/g++.dg/cpp23/subscript7.C
new file mode 100644
index 00000000000..bb811974433
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp23/subscript7.C
@@ -0,0 +1,17 @@
+// PR c++/103460
+// { dg-do compile }
+// { dg-options "-std=c++23" }
+
+struct S {
+  int &operator[] (int, ...);
+} s;
+struct T {
+  int &operator[] (auto...);
+} t;
+struct U {
+  int &operator[] (...);
+} u;
+
+int a = s[1] + s[2, 1] + s[3, 2, 1] + s[4, 3, 2, 1]
+	+ t[0.0] + t[nullptr, s, 42]
+	+ u[] + u[42] + u[1.5L, 1LL];


                 reply	other threads:[~2022-03-10 14:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220310142855.90CAC3857813@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@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).