public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-2501] c++: C++23 operator[] allows default arguments
Date: Tue,  6 Sep 2022 20:21:17 +0000 (GMT)	[thread overview]
Message-ID: <20220906202117.BE2643850855@sourceware.org> (raw)

https://gcc.gnu.org/g:0a2fba3697411c07a8330abfe7460ce62bce5e7f

commit r13-2501-g0a2fba3697411c07a8330abfe7460ce62bce5e7f
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Sep 6 14:18:39 2022 -0400

    c++: C++23 operator[] allows default arguments
    
    This usage was intended to be allowed by P2128, but it didn't make it into
    the final wording.  Fixed by CWG 2507.
    
            DR2507
    
    gcc/cp/ChangeLog:
    
            * decl.cc (grok_op_properties): Return sooner for C++23 op[].
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp23/subscript8.C: New test.

Diff:
---
 gcc/cp/decl.cc                          | 11 +++++------
 gcc/testsuite/g++.dg/cpp23/subscript8.C |  7 +++++++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index b72b2a8456b..6d20765f40c 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -15331,6 +15331,11 @@ grok_op_properties (tree decl, bool complain)
        "operator ()".  */
     return true;
 
+  /* C++23 allows an arbitrary number of parameters and default arguments for
+     operator[], and none of the other checks below apply.  */
+  if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
+    return true;
+
   if (operator_code == COND_EXPR)
     {
       /* 13.4.0.3 */
@@ -15344,10 +15349,6 @@ 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;
@@ -15408,8 +15409,6 @@ grok_op_properties (tree decl, bool complain)
     case OVL_OP_FLAG_BINARY:
       if (arity != 2)
 	{
-	  if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
-	    break;
 	  error_at (loc,
 		    methodp
 		    ? G_("%qD must have exactly one argument")
diff --git a/gcc/testsuite/g++.dg/cpp23/subscript8.C b/gcc/testsuite/g++.dg/cpp23/subscript8.C
new file mode 100644
index 00000000000..fe000359d41
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp23/subscript8.C
@@ -0,0 +1,7 @@
+// DR2507: Allow default arguments
+// { dg-additional-options {-std=c++23} }
+
+struct A
+{
+  void operator[](int, int = 42);
+};

                 reply	other threads:[~2022-09-06 20:21 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=20220906202117.BE2643850855@sourceware.org \
    --to=jason@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).