From 71b6cb2bbccba8922a8c7e9082a13a02dee7e57d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 6 Mar 2019 19:46:32 +0100 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/init.c | 9 +++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ext/flexary34.C | 10 ++++++++++ 4 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/flexary34.C 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 (); } -- 2.30.2