If we don't like the designator, we should fail pleasantly.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
commit be2b8cf9756a4ca4be6583f65fc4388ada2a5b77
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon May 13 13:26:12 2013 -0400

    	PR c++/57041
    	* decl.c (reshape_init_class): Handle error_mark_node.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3854135..acc8371 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5200,6 +5200,9 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
       /* Handle designated initializers, as an extension.  */
       if (d->cur->index)
 	{
+	  if (d->cur->index == error_mark_node)
+	    return error_mark_node;
+
 	  if (TREE_CODE (d->cur->index) == INTEGER_CST)
 	    {
 	      if (complain & tf_error)
diff --git a/gcc/testsuite/g++.dg/ext/desig6.C b/gcc/testsuite/g++.dg/ext/desig6.C
new file mode 100644
index 0000000..30882a6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/desig6.C
@@ -0,0 +1,18 @@
+// PR c++/57041
+// { dg-options "-std=gnu++11" }
+// { dg-prune-output "error:" }
+
+template<typename T>
+union u {
+  T a;
+  char b;
+};
+
+template<typename T>
+u<T> make_u(T t) {
+  return { .a = t };
+}
+
+int main() {
+  return make_u<int>(1).a;
+}

Reply via email to