commit 4f51a88ed61f69fd483a46b93f0ba9cff352324a
Author: Jason Merrill <jason@redhat.com>
Date: Mon Jun 18 21:20:29 2018 -0400
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.
@@ -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);
new file mode 100644
@@ -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);
+}