From: Roger Sayle Date: Tue, 7 Jun 2022 06:54:13 +0000 (+0100) Subject: PR c++/96442: Improved error recovery in enumerations. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6dd194e2ce201d057e4faaecc36d19e0d3695f57;p=platform%2Fupstream%2Fgcc.git 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 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. --- diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 90b12d6..7add82a 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -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 index 0000000..235bb11 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/pr96442.C @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +enum struct a : struct {}; +template enum class a : class c{}; +enum struct a {b}; +// { dg-excess-errors "" }