From: Marek Polacek Date: Wed, 14 Dec 2016 20:41:43 +0000 (+0000) Subject: re PR c++/72775 (internal compiler error: in finish_expr_stmt, at cp/semantics.c... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=964b79eb330d5df3e851696e2d0bfa30b0e0307b;p=gcc.git re PR c++/72775 (internal compiler error: in finish_expr_stmt, at cp/semantics.c:677) PR c++/72775 * init.c (perform_member_init): Diagnose member initializer for flexible array member. * g++.dg/ext/flexary12.C: Adjust dg-error. * g++.dg/ext/flexary20.C: New. * g++.dg/ext/flexary21.C: New. From-SVN: r243669 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4061bedab8b..a08c93a755e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-12-14 Marek Polacek + + PR c++/72775 + * init.c (perform_member_init): Diagnose member initializer for + flexible array member. + 2016-12-14 Nathan Sidwell PR c++/78701 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index b4b6cdb0a4c..47428b96f3d 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -800,6 +800,14 @@ perform_member_init (tree member, tree init) in that case. */ init = build_x_compound_expr_from_list (init, ELK_MEM_INIT, tf_warning_or_error); + if (TREE_CODE (type) == ARRAY_TYPE + && TYPE_DOMAIN (type) == NULL_TREE + && init != NULL_TREE) + { + error_at (DECL_SOURCE_LOCATION (current_function_decl), + "member initializer for flexible array member"); + inform (DECL_SOURCE_LOCATION (member), "%q#D initialized", member); + } if (init) finish_expr_stmt (cp_build_modify_expr (input_location, decl, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7875060bcb7..5026f07b5dc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2016-12-14 Marek Polacek + + PR c++/72775 + * g++.dg/ext/flexary12.C: Adjust dg-error. + * g++.dg/ext/flexary20.C: New. + * g++.dg/ext/flexary21.C: New. + 2016-12-14 Uros Bizjak PR target/59874 diff --git a/gcc/testsuite/g++.dg/ext/flexary12.C b/gcc/testsuite/g++.dg/ext/flexary12.C index 3d8c8059223..db80bf408f5 100644 --- a/gcc/testsuite/g++.dg/ext/flexary12.C +++ b/gcc/testsuite/g++.dg/ext/flexary12.C @@ -44,7 +44,7 @@ struct D { D (); }; -D::D (): +D::D (): // { dg-error "member initializer for flexible array member" } a ("c") // { dg-error "incompatible types in assignment of .const char \\\[2\\\]. to .int \\\[\\\]." } { } diff --git a/gcc/testsuite/g++.dg/ext/flexary20.C b/gcc/testsuite/g++.dg/ext/flexary20.C new file mode 100644 index 00000000000..2c8ab2960f7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flexary20.C @@ -0,0 +1,49 @@ +// PR c++/72775 +// { dg-do compile { target c++11 } } +// { dg-options -Wno-pedantic } + +struct S { + int i; + char a[] = "foo"; + S () {} // { dg-error "member initializer for flexible array member" } +}; + +struct T { // { dg-error "member initializer for flexible array member" } + int i; + char a[] = "foo"; +}; + +struct U { + int i; + char a[] = "foo"; + U (); +}; + +U::U() {} // { dg-error "member initializer for flexible array member" } + +int +main () +{ + struct T t; +} + +struct V { + int i; + struct W { // { dg-error "member initializer for flexible array member" } + int j; + char a[] = "foo"; + } w; + V () {} +}; + +template +struct X { // { dg-error "member initializer for flexible array member" } + int i; + T a[] = "foo"; +}; + +void +fn () +{ + struct X x; +} diff --git a/gcc/testsuite/g++.dg/ext/flexary21.C b/gcc/testsuite/g++.dg/ext/flexary21.C new file mode 100644 index 00000000000..5675bf6f0d6 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flexary21.C @@ -0,0 +1,15 @@ +// PR c++/72775 +// { dg-do compile { target c++11 } } +// { dg-options -Wno-pedantic } + +struct S { + int i; + char a[]; + S () : a("bob") {} // { dg-error "member initializer for flexible array member" } +}; + +struct T { + int i; + char a[] = "bob"; + T () : a("bob") {} // { dg-error "member initializer for flexible array member" } +};