From 50b27938f70819e2453bcd72a80a6a4c2b9e2fcb Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 18 Jan 2018 17:11:43 +0000 Subject: [PATCH] re PR c++/81013 (ICE with invalid union in class hierarchy) /cp 2018-01-18 Paolo Carlini PR c++/81013 * decl.c (xref_basetypes): Early return upon error about derived union. /testsuite 2018-01-18 Paolo Carlini PR c++/81013 * g++.dg/inherit/union3.C: New. From-SVN: r256856 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 5 ++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/inherit/union3.C | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/inherit/union3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0cacefa674d..2de9dcb06d5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-01-18 Paolo Carlini + + PR c++/81013 + * decl.c (xref_basetypes): Early return upon error about derived + union. + 2018-01-18 Nathan Sidwell PR c++/83160 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 12022a2fdd8..32ac81fc271 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -13801,7 +13801,10 @@ xref_basetypes (tree ref, tree base_list) CLASSTYPE_NON_LAYOUT_POD_P (ref) = true; if (TREE_CODE (ref) == UNION_TYPE) - error ("derived union %qT invalid", ref); + { + error ("derived union %qT invalid", ref); + return; + } } if (max_bases > 1) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f9674a9ee90..3110c486400 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-18 Paolo Carlini + + PR c++/81013 + * g++.dg/inherit/union3.C: New. + 2018-01-18 Christophe Lyon * gcc.dg/rtl/arm/stl-cond.c: Enable on arm*. diff --git a/gcc/testsuite/g++.dg/inherit/union3.C b/gcc/testsuite/g++.dg/inherit/union3.C new file mode 100644 index 00000000000..c13b39768db --- /dev/null +++ b/gcc/testsuite/g++.dg/inherit/union3.C @@ -0,0 +1,16 @@ +// PR c++/81013 + +struct A +{ + virtual void foo() const; +}; + +union B : A // { dg-error "derived union 'B' invalid" } +{ + void foo() const; +}; + +void bar(const B& b) +{ + b.foo(); +} -- 2.30.2