[gcc r14-8239] c++: ICE when xobj is not the first parm [PR113389]

Marek Polacek mpolacek@gcc.gnu.org
Thu Jan 18 14:12:22 GMT 2024


https://gcc.gnu.org/g:9840e0be78150b0ef6e29975a6244698d5a5580c

commit r14-8239-g9840e0be78150b0ef6e29975a6244698d5a5580c
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Jan 17 19:16:32 2024 -0500

    c++: ICE when xobj is not the first parm [PR113389]
    
    In grokdeclarator/cdk_function the comment says that the find_xobj_parm
    lambda clears TREE_PURPOSE so that we can correctly detect an xobj that
    is not the first parameter.  That's all good, but we should also clear
    the TREE_PURPOSE once we've given the error, otherwise we crash later in
    check_default_argument because the 'this' TREE_PURPOSE lacks a type.
    
            PR c++/113389
    
    gcc/cp/ChangeLog:
    
            * decl.cc (grokdeclarator) <case cdk_function>: Set TREE_PURPOSE to
            NULL_TREE when emitting an error.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp23/explicit-obj-diagnostics10.C: New test.

Diff:
---
 gcc/cp/decl.cc                                          | 1 +
 gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics10.C | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 322e48dee2e..3e41fd4fa31 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -13391,6 +13391,7 @@ grokdeclarator (const cp_declarator *declarator,
 		  if (TREE_PURPOSE (parm) != this_identifier)
 		    continue;
 		  bad_xobj_parm_encountered = true;
+		  TREE_PURPOSE (parm) = NULL_TREE;
 		  gcc_rich_location bad_xobj_parm
 		    (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
 		  error_at (&bad_xobj_parm,
diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics10.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics10.C
new file mode 100644
index 00000000000..354823db166
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics10.C
@@ -0,0 +1,8 @@
+// PR c++/113389
+// { dg-do compile { target c++23 } }
+
+struct A {
+  void foo(A, this A);	// { dg-error "only the first parameter" }
+  void qux(A, this A,	// { dg-error "only the first parameter" }
+	   this A);	// { dg-error "only the first parameter" }
+};


More information about the Gcc-cvs mailing list