On 3/10/22 04:34, Jakub Jelinek wrote:
Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

2022-03-10  Jakub Jelinek  <ja...@redhat.com>

        PR c++/103460
        * decl.cc (grok_op_properties): Allow variadic operator[] for
        C++23.

        * g++.dg/cpp23/subscript7.C: New test.

--- gcc/cp/decl.cc.jj   2022-03-09 15:24:57.285926439 +0100
+++ gcc/cp/decl.cc      2022-03-09 16:56:41.053901657 +0100
@@ -15214,6 +15214,9 @@ grok_op_properties (tree decl, bool comp
        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 comp
      }
/* 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;
--- gcc/testsuite/g++.dg/cpp23/subscript7.C.jj  2022-03-09 17:02:22.915179262 
+0100
+++ gcc/testsuite/g++.dg/cpp23/subscript7.C     2022-03-09 17:02:18.446240994 
+0100
@@ -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];

        Jakub


Reply via email to