The check for matching type when initializing a subaggregate needed to know about flexible array types.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 251d142a1046a1a6cfcbafd29fabd163ec78d7cb Author: Jason Merrill <ja...@redhat.com> Date: Mon Apr 17 16:55:21 2017 -0400 PR c++/80179 - ICE with initialized flexible array member. * constexpr.c (verify_ctor_sanity): Handle flexible array members. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 9dde4a4..366d562 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2643,8 +2643,16 @@ verify_ctor_sanity (const constexpr_ctx *ctx, tree type) /* We used to check that ctx->ctor was empty, but that isn't the case when the object is zero-initialized before calling the constructor. */ if (ctx->object) - gcc_assert (same_type_ignoring_top_level_qualifiers_p - (type, TREE_TYPE (ctx->object))); + { + tree otype = TREE_TYPE (ctx->object); + gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, otype) + /* Handle flexible array members. */ + || (TREE_CODE (otype) == ARRAY_TYPE + && TYPE_DOMAIN (otype) == NULL_TREE + && TREE_CODE (type) == ARRAY_TYPE + && (same_type_ignoring_top_level_qualifiers_p + (TREE_TYPE (type), TREE_TYPE (otype))))); + } gcc_assert (!ctx->object || !DECL_P (ctx->object) || *(ctx->values->get (ctx->object)) == ctx->ctor); } diff --git a/gcc/testsuite/g++.dg/ext/flexary24.C b/gcc/testsuite/g++.dg/ext/flexary24.C new file mode 100644 index 0000000..c25e540 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flexary24.C @@ -0,0 +1,12 @@ +// PR c++/80179 +// { dg-options "" } + +struct S { + int n; + const char *a[]; +}; + +void bar (const char *a) +{ + static const S t = { 1, { a, "b" } }; +}