* pt.c (tsubst_expr) [DECL_EXPR]: Handle an anonymous union type
used to declare a named variable.
From-SVN: r261757
+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.
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);
--- /dev/null
+// 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);
+}