From: Jason Merrill Date: Tue, 19 Jun 2018 18:46:51 +0000 (-0400) Subject: PR c++/86192 - ICE with anonymous union passed to template. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0e570cf8b6e47bc3ee9031eae70acf57bc5fd655;p=gcc.git PR c++/86192 - ICE with anonymous union passed to template. * pt.c (tsubst_expr) [DECL_EXPR]: Handle an anonymous union type used to declare a named variable. From-SVN: r261757 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7c903c55337..d4d5e5b44a9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-06-19 Jason Merrill + + PR c++/86192 - ICE with anonymous union passed to template. + * pt.c (tsubst_expr) [DECL_EXPR]: Handle an anonymous union type + used to declare a named variable. + 2018-06-18 Jason Merrill * tree.c (cp_expr_location): New. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1ecc6fb373d..3386385b3f8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16678,7 +16678,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, do. */ if (VAR_P (decl)) DECL_TEMPLATE_INSTANTIATED (decl) = 1; - if (VAR_P (decl) + if (VAR_P (decl) && !DECL_NAME (decl) && ANON_AGGR_TYPE_P (TREE_TYPE (decl))) /* Anonymous aggregates are a special case. */ finish_anon_union (decl); diff --git a/gcc/testsuite/g++.dg/template/anonunion3.C b/gcc/testsuite/g++.dg/template/anonunion3.C new file mode 100644 index 00000000000..1ac8165fa78 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/anonunion3.C @@ -0,0 +1,16 @@ +// PR c++/86192 +// { dg-do compile { target c++11 } } + +extern "C" int printf (const char *, ...); + +template static char const * f(T *t) { + T u(*t); + u.x = "hello world"; + printf("%s\n", u.x); + return "initialized"; +} + +int main() { + union { char const *x = f(this); }; + printf("%s\n", x); +}