[PR c++/84729] convert new init to array elt type

Alexandre Oliva aoliva@redhat.com
Sat Mar 10 11:57:00 GMT 2018


A parenthesized initializer is only accepted when new()ing an array in
permissive mode.  We were not careful, however, to convert the
TREE_LIST initializer to the array element type in this extension.
This patch fixes it: after turning the TREE_LIST initializer to a
compound_expr, we convert it to the base type.

Regstrapped on i686- and x86_64-linux-gnu.  Ok to install?

for  gcc/cp/ChangeLog

	PR c++/84729
	* init.c (build_vec_init): Convert tree list to base type.

for  gcc/testsuite/ChangeLog

	PR c++/84729
	* g++.dg/pr84729.C: New.
---
 gcc/cp/init.c                  |   10 ++++++++--
 gcc/testsuite/g++.dg/pr84729.C |    7 +++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr84729.C

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 15cee17c780c..cb62f4886e6d 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -4405,8 +4405,14 @@ build_vec_init (tree base, tree maxindex, tree init,
 	  else
 	    {
 	      if (TREE_CODE (init) == TREE_LIST)
-		init = build_x_compound_expr_from_list (init, ELK_INIT,
-							complain);
+		{
+		  init = build_x_compound_expr_from_list (init, ELK_INIT,
+							  complain);
+		  init
+		    = convert_for_initialization (NULL_TREE, type, init,
+						  LOOKUP_IMPLICIT, ICR_INIT,
+						  NULL_TREE, 0, complain);
+		}
 	      elt_init = (init == error_mark_node
 			  ? error_mark_node
 			  : build2 (INIT_EXPR, type, to, init));
diff --git a/gcc/testsuite/g++.dg/pr84729.C b/gcc/testsuite/g++.dg/pr84729.C
new file mode 100644
index 000000000000..6ca7fb0032f5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr84729.C
@@ -0,0 +1,7 @@
+// { dg-do compile }
+// { dg-options "-fpermissive" }
+
+typedef int b[2];
+void a() {
+  new b(a); // { dg-warning "parenthesized initializer in array new|invalid conversion" }
+}

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer



More information about the Gcc-patches mailing list