https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102295
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:818c505188ff5cd8eb048eb0e614c4ef732225bd commit r12-3526-g818c505188ff5cd8eb048eb0e614c4ef732225bd Author: Jakub Jelinek <ja...@redhat.com> Date: Tue Sep 14 16:56:30 2021 +0200 c++: Update DECL_*SIZE for objects with flexible array members with initializers [PR102295] The C FE updates DECL_*SIZE for vars which have initializers for flexible array members for many years, but C++ FE kept DECL_*SIZE the same as the type size (i.e. as if there were zero elements in the flexible array member). This results e.g. in ELF symbol sizes being too small. Note, if the flexible array member is initialized only with non-constant initializers, we have a worse bug that this patch doesn't solve, the splitting of initializers into constant and dynamic initialization removes the initializer and we don't have just wrong DECL_*SIZE, but nothing is emitted when emitting those vars into assembly either and so the dynamic initialization clobbers other vars that may overlap the variable. I think we need keep an empty CONSTRUCTOR elt in DECL_INITIAL for the flexible array member in that case. 2021-09-14 Jakub Jelinek <ja...@redhat.com> PR c++/102295 * decl.c (layout_var_decl): For aggregates ending with a flexible array member, add the size of the initializer for that member to DECL_SIZE and DECL_SIZE_UNIT. * g++.target/i386/pr102295.C: New test.