[C++ PATCH] Fix regression due to reshape_init being called multiple times (PR c++/69658)

Jakub Jelinek jakub@redhat.com
Thu Feb 4 19:56:00 GMT 2016


Hi!

As mentioned in the PR, it seems reshape_init isn't prepared to be called
on the result of earlier reshape_init call, but since the recent Paolo's
changes expand_default_init can call it the second time.

The following patch attempts to narrow it down to the case where it
has not been called yet, and not call it when it is called indirectly
from check_initializer that has already called reshape_init.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-02-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/69658
	* init.c (expand_default_init): Only call reshape_init
	in the direct-initialization from an initializer list case.

	* g++.dg/init/pr69658.C: New test.

--- gcc/cp/init.c.jj	2016-01-29 12:12:46.000000000 +0100
+++ gcc/cp/init.c	2016-02-04 18:53:26.865318337 +0100
@@ -1636,16 +1636,17 @@ expand_default_init (tree binfo, tree tr
       gcc_checking_assert ((flags & LOOKUP_ONLYCONVERTING) == 0
 			   && TREE_CHAIN (init) == NULL_TREE);
       init = TREE_VALUE (init);
+      /* Only call reshape_init if it has not been called earlier
+	 by the callers.  */
+      if (BRACE_ENCLOSED_INITIALIZER_P (init) && CP_AGGREGATE_TYPE_P (type))
+	init = reshape_init (type, init, complain);
     }
 
   if (init && BRACE_ENCLOSED_INITIALIZER_P (init)
       && CP_AGGREGATE_TYPE_P (type))
     /* A brace-enclosed initializer for an aggregate.  In C++0x this can
        happen for direct-initialization, too.  */
-    {
-      init = reshape_init (type, init, complain);
-      init = digest_init (type, init, complain);
-    }
+    init = digest_init (type, init, complain);
 
   /* A CONSTRUCTOR of the target's type is a previously digested
      initializer, whether that happened just above or in
--- gcc/testsuite/g++.dg/init/pr69658.C.jj	2016-02-04 18:55:46.862390961 +0100
+++ gcc/testsuite/g++.dg/init/pr69658.C	2016-02-04 18:54:58.000000000 +0100
@@ -0,0 +1,6 @@
+// PR c++/69658
+// { dg-do compile }
+
+struct S { S (int); };
+struct T { char n[6]; S s; };
+T t[1] = { { "foo", 1 } };	// { dg-bogus "C99 designator" }

	Jakub



More information about the Gcc-patches mailing list