From: Jakub Jelinek Date: Wed, 6 Mar 2019 18:46:32 +0000 (+0100) Subject: re PR c++/87148 (backward compatibility issue to take char [] as incomplete type) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=71b6cb2bbccba8922a8c7e9082a13a02dee7e57d;p=gcc.git re PR c++/87148 (backward compatibility issue to take char [] as incomplete type) PR c++/87148 * init.c (build_value_init_noctor): Ignore flexible array members. * g++.dg/ext/flexary34.C: New test. From-SVN: r269434 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a076fa9a255..b0c1f88c6a2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-03-06 Jakub Jelinek + + PR c++/87148 + * init.c (build_value_init_noctor): Ignore flexible array members. + 2019-03-06 Jason Merrill PR c++/89576 - if constexpr of lambda capture. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index eb3b504d708..79a93a297a9 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -419,6 +419,15 @@ build_value_init_noctor (tree type, tsubst_flags_t complain) if (ftype == error_mark_node) continue; + /* Ignore flexible array members for value initialization. */ + if (TREE_CODE (ftype) == ARRAY_TYPE + && !COMPLETE_TYPE_P (ftype) + && !TYPE_DOMAIN (ftype) + && COMPLETE_TYPE_P (TREE_TYPE (ftype)) + && (next_initializable_field (DECL_CHAIN (field)) + == NULL_TREE)) + continue; + /* We could skip vfields and fields of types with user-defined constructors, but I think that won't improve performance at all; it should be simpler in general just diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9a65e3a8147..4175bc4b246 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-06 Jakub Jelinek + + PR c++/87148 + * g++.dg/ext/flexary34.C: New test. + 2019-03-06 Peter Bergner PR rtl-optimization/88845 diff --git a/gcc/testsuite/g++.dg/ext/flexary34.C b/gcc/testsuite/g++.dg/ext/flexary34.C new file mode 100644 index 00000000000..bbbbf852692 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flexary34.C @@ -0,0 +1,10 @@ +// PR c++/87148 +// { dg-do compile } +// { dg-options "-pedantic" } + +struct Tst { int i; char t[]; }; // { dg-warning "forbids flexible array member" } + +Tst t {}; // { dg-warning "extended initializer lists only available with" "" { target c++98_only } } +Tst u = Tst(); +void foo () { Tst u = {}; } +Tst *bar () { return new Tst (); }