PR c++/96442: Improved error recovery in enumerations.

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.
This commit is contained in:
Roger Sayle 2022-06-07 07:54:13 +01:00
parent c4320bde42
commit 6dd194e2ce
2 changed files with 11 additions and 2 deletions

View 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

View File

@ -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 "" }