]> gcc.gnu.org Git - gcc.git/commitdiff
PR c++/96442: Improved error recovery in enumerations.
authorRoger Sayle <roger@nextmovesoftware.com>
Tue, 7 Jun 2022 06:54:13 +0000 (07:54 +0100)
committerRoger Sayle <roger@nextmovesoftware.com>
Tue, 7 Jun 2022 06:54:13 +0000 (07:54 +0100)
This patch is a revised fix for PR c++/96442 providing a cleaner
solution, setting ENUM_UNDERLYING_TYPE to integer_type_node when
issuing an error, so that this invariant holds during the parser's
error recovery.

2022-06-07  Roger Sayle  <roger@nextmovesoftware.com>

gcc/cp/ChangeLog
PR c++/96442
* decl.cc (start_enum): When emitting a "must be integral" error,
set ENUM_UNDERLYING_TYPE to integer_type_node, to avoid an ICE
downstream in build_enumeration.

gcc/testsuite/ChangeLog
PR c++/96442
* g++.dg/parse/pr96442.C: New test case.

gcc/cp/decl.cc
gcc/testsuite/g++.dg/parse/pr96442.C [new file with mode: 0644]

index 90b12d69414c851966bce0988f9ddeaa1a0bcde9..7add82aa39e37f5949700fe26b12d37dcd88506d 100644 (file)
@@ -16314,8 +16314,11 @@ start_enum (tree name, tree enumtype, tree underlying_type,
       else if (dependent_type_p (underlying_type))
        ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
       else
-        error ("underlying type %qT of %qT must be an integral type", 
-               underlying_type, enumtype);
+       {
+         error ("underlying type %qT of %qT must be an integral type", 
+                underlying_type, enumtype);
+         ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
+       }
     }
 
   /* If into a template class, the returned enum is always the first
diff --git a/gcc/testsuite/g++.dg/parse/pr96442.C b/gcc/testsuite/g++.dg/parse/pr96442.C
new file mode 100644 (file)
index 0000000..235bb11
--- /dev/null
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+enum struct a : struct {};
+template <class b> enum class a : class c{};
+enum struct a {b};
+// { dg-excess-errors "" }
This page took 0.085556 seconds and 5 git commands to generate.