From 8fdddd3d837dac9f062236ce97e7c0be59638df1 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 22 Feb 2017 19:33:13 +0000 Subject: [PATCH] re PR c++/79657 (ICE on invalid c++ code in finish_underlying_type cp/semantics.c:3849) PR c++/79657 * semantics.c (finish_underlying_type): Bail out for incomplete enums. * g++.dg/ext/underlying_type12.C: New test. From-SVN: r245658 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/semantics.c | 3 ++- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/ext/underlying_type12.C | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/underlying_type12.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 38b60bc695f..c036f8cf0e0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -6,6 +6,9 @@ * pt.c (tsubst_attribute): If tsubst_pack_expansion fails, return error_mark_node. + PR c++/79657 + * semantics.c (finish_underlying_type): Bail out for incomplete enums. + 2017-02-21 Jason Merrill PR c++/50308 - wrong deprecated warning with ADL diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 6ba7c13d6ec..67f8b9264f1 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3838,7 +3838,8 @@ finish_underlying_type (tree type) return underlying_type; } - complete_type (type); + if (!complete_type_or_else (type, NULL_TREE)) + return error_mark_node; if (TREE_CODE (type) != ENUMERAL_TYPE) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 628529b535c..31e7b4fb79e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -4,6 +4,9 @@ * g++.dg/cpp0x/alignas10.C: New test. * g++.dg/cpp0x/alignas9.C: New test. + PR c++/79657 + * g++.dg/ext/underlying_type12.C: New test. + 2017-02-22 Jakub Jelinek PR target/70465 diff --git a/gcc/testsuite/g++.dg/ext/underlying_type12.C b/gcc/testsuite/g++.dg/ext/underlying_type12.C new file mode 100644 index 00000000000..050ecf270b8 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/underlying_type12.C @@ -0,0 +1,6 @@ +// PR c++/79657 +// { dg-do compile { target c++11 } } + +enum A { x }; +enum B { a = (__underlying_type (A)) 1 }; +enum C { b = (__underlying_type (C)) 1 }; // { dg-error "incomplete" } -- 2.30.2