This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PR c++/84729] convert new init to array elt type
On Mar 20, 2018, Jason Merrill <jason@redhat.com> wrote:
> On Sat, Mar 10, 2018 at 6:57 AM, Alexandre Oliva <aoliva@redhat.com> wrote:
>> 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.
> I think I'd rather turn the permerror into a hard error than improve
> support for a deprecated extension.
Like this?
[PR c++/84729] convert new init to array elt type
A parenthesized initializer was 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.
Instead of fixing it, converting the initializer to the base type
after turning the TREE_LIST initializer to a compound_expr, we disable
this deprecated extension.
Regstrapping. Ok to install if it passes?
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 | 4 ++--
gcc/testsuite/g++.dg/pr84729.C | 7 +++++++
2 files changed, 9 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..9091eaa90267 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -3370,8 +3370,8 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
else if (*init)
{
if (complain & tf_error)
- permerror (input_location,
- "parenthesized initializer in array new");
+ error_at (input_location,
+ "parenthesized initializer in array new");
else
return error_mark_node;
vecinit = build_tree_list_vec (*init);
diff --git a/gcc/testsuite/g++.dg/pr84729.C b/gcc/testsuite/g++.dg/pr84729.C
new file mode 100644
index 000000000000..e5d689e0460c
--- /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-error "parenthesized initializer in array new" }
+}
--
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