]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix checking assert upon invalid class definition [PR116740]
authorSimon Martin <simon@nasilyan.com>
Wed, 5 Mar 2025 08:08:57 +0000 (09:08 +0100)
committerSimon Martin <simon@nasilyan.com>
Wed, 5 Mar 2025 08:11:13 +0000 (09:11 +0100)
A checking assert triggers upon the following invalid code since
GCC 11:

=== cut here ===
class { a (struct b;
} struct b
=== cut here ===

The problem is that during error recovery, we call
set_identifier_type_value_with_scope for B in the global namespace, and
the checking assert added via r11-7228-g8f93e1b892850b fails.

This patch relaxes that assert to not fail if we've seen a parser error
(it a generalization of another fix done to that checking assert via
r11-7266-g24bf79f1798ad1).

PR c++/116740

gcc/cp/ChangeLog:

* name-lookup.cc (set_identifier_type_value_with_scope): Don't
fail assert with ill-formed input.

gcc/testsuite/ChangeLog:

* g++.dg/parse/crash80.C: New test.

gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/parse/crash80.C [new file with mode: 0644]

index d1abb205bc7fcbdfeb227732de28c447ef7df1aa..742e5d289dc91e3eaba21b49aeb2a1c39e032bff 100644 (file)
@@ -5101,10 +5101,8 @@ set_identifier_type_value_with_scope (tree id, tree decl, cp_binding_level *b)
   if (b->kind == sk_namespace)
     /* At namespace scope we should not see an identifier type value.  */
     gcc_checking_assert (!REAL_IDENTIFIER_TYPE_VALUE (id)
-                        /* We could be pushing a friend underneath a template
-                           parm (ill-formed).  */
-                        || (TEMPLATE_PARM_P
-                            (TYPE_NAME (REAL_IDENTIFIER_TYPE_VALUE (id)))));
+                        /* But we might end up here with ill-formed input.  */
+                        || seen_error ());
   else
     {
       /* Push the current type value, so we can restore it later  */
diff --git a/gcc/testsuite/g++.dg/parse/crash80.C b/gcc/testsuite/g++.dg/parse/crash80.C
new file mode 100644 (file)
index 0000000..cd9216a
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/116740
+// { dg-do "compile" }
+
+class K {
+  int a(struct b; // { dg-error "expected '\\)'" }
+};
+struct b {};