aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2018-06-19 14:46:51 -0400
committerJason Merrill <jason@gcc.gnu.org>2018-06-19 14:46:51 -0400
commit0e570cf8b6e47bc3ee9031eae70acf57bc5fd655 (patch)
tree78bfb618b65263a8deb2a7b1c79c25ddc4602dc1
parent9a775e9df5f72a8a9627fca8d412361562c8186a (diff)
downloadgcc-0e570cf8b6e47bc3ee9031eae70acf57bc5fd655.zip
gcc-0e570cf8b6e47bc3ee9031eae70acf57bc5fd655.tar.gz
gcc-0e570cf8b6e47bc3ee9031eae70acf57bc5fd655.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c2
-rw-r--r--gcc/testsuite/g++.dg/template/anonunion3.C16
3 files changed, 23 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 7c903c5..d4d5e5b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-06-19 Jason Merrill <jason@redhat.com>
+
+ 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 <jason@redhat.com>
* tree.c (cp_expr_location): New.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1ecc6fb..3386385 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 0000000..1ac8165
--- /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<typename T> 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);
+}