]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fix bogus error with xobj member function [PR125330]
authorMarek Polacek <polacek@redhat.com>
Tue, 19 May 2026 00:51:06 +0000 (20:51 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 21 May 2026 21:43:21 +0000 (17:43 -0400)
In this test since r17-472 we issue a bogus "not declared in this scope"
error when parsing the requires because we failed to pushdecl.  Xobj
parameters reuse the default argument field (in _parameter_declaration)
so we also have to check this_identifier.

PR c++/125330

gcc/cp/ChangeLog:

* parser.cc (cp_parser_parameter_declaration_list): Also
pushdecl when parameter->default_argument is this_identifier.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/explicit-obj-basic8.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp23/explicit-obj-basic8.C [new file with mode: 0644]

index 1ab462160da8996990eaa24cd616c7049d801c33..0c78c437019fb73bf4d850e9ca9b51334b1b6e08 100644 (file)
@@ -28347,7 +28347,8 @@ cp_parser_parameter_declaration_list (cp_parser* parser,
          /* If we saw a default argument, we've already pushed this decl.
             (An ill-formed default argument should have been parsed to
             error_mark_node.)  */
-         else if (!parameter->default_argument)
+         else if (!parameter->default_argument
+                  || parameter->default_argument == this_identifier)
            decl = pushdecl (decl);
        }
 
diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-basic8.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-basic8.C
new file mode 100644 (file)
index 0000000..6824bcb
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/125330
+// { dg-do compile { target c++23 } }
+
+struct T {
+  template<typename Self>
+  void foo(this Self const &x) requires requires { x.bar(); }
+    { x.bar(); }
+};