]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/86192 - ICE with anonymous union passed to template.
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Jun 2018 18:46:51 +0000 (18:46 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Jun 2018 18:46:51 +0000 (18:46 +0000)
* pt.c (tsubst_expr) [DECL_EXPR]: Handle an anonymous union type
used to declare a named variable.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@261757 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/template/anonunion3.C [new file with mode: 0644]

index 7c903c553378033fc368800bbd470b39f64a9e42..d4d5e5b44a99199b6f6b93b219b80364b3af5cfa 100644 (file)
@@ -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.
index 1ecc6fb373db092f1e04b48bfd2fec2062150436..3386385b3f88dbd02e534e92883e0c9faf357679 100644 (file)
@@ -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 (file)
index 0000000..1ac8165
--- /dev/null
@@ -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);
+}