Patchwork C++ PATCH for c++/57041 (ICE with designated initializer)

login
register
mail settings
Submitter Jason Merrill
Date May 13, 2013, 7:20 p.m.
Message ID <51913CE5.5020207@redhat.com>
Download mbox | patch
Permalink /patch/243500/
State New
Headers show

Comments

Jason Merrill - May 13, 2013, 7:20 p.m.
If we don't like the designator, we should fail pleasantly.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.

Patch

commit be2b8cf9756a4ca4be6583f65fc4388ada2a5b77
Author: Jason Merrill <jason@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;
+}