diff options
-rw-r--r-- | gcc/cp/constexpr.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/no_unique_address8.C | 11 |
2 files changed, 27 insertions, 2 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index b787919..c121753 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -3474,7 +3474,9 @@ get_or_insert_ctor_field (tree ctor, tree index, int pos_hint = -1) } else { - gcc_assert (TREE_CODE (index) == FIELD_DECL); + gcc_assert (TREE_CODE (index) == FIELD_DECL + && (same_type_ignoring_top_level_qualifiers_p + (DECL_CONTEXT (index), TREE_TYPE (ctor)))); /* We must keep the CONSTRUCTOR's ELTS in FIELD order. Usually we meet initializers in that order, but it is @@ -5277,7 +5279,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, }; CONSTRUCTOR_ELTS (ary_ctor)->quick_push (elt); } - + *valp = ary_ctor; } @@ -5289,6 +5291,18 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, type = refs->pop(); tree index = refs->pop(); + if (TREE_CODE (index) == FIELD_DECL + && !(same_type_ignoring_top_level_qualifiers_p + (DECL_CONTEXT (index), TREE_TYPE (*valp)))) + { + /* INDEX isn't a member of *valp. This can happen if it's a member + of an empty base which isn't represented with a FIELD_DECL. Stop + trying to build a CONSTRUCTOR for the inner target; we'll notice + this disconnect again below and just return init. */ + gcc_assert (is_empty_class (DECL_CONTEXT (index))); + break; + } + if (code == UNION_TYPE && CONSTRUCTOR_NELTS (*valp) && CONSTRUCTOR_ELT (*valp, 0)->index != index) { diff --git a/gcc/testsuite/g++.dg/cpp2a/no_unique_address8.C b/gcc/testsuite/g++.dg/cpp2a/no_unique_address8.C new file mode 100644 index 0000000..8b63ca3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/no_unique_address8.C @@ -0,0 +1,11 @@ +// PR c++/98463 +// { dg-do compile { target c++11 } } + +template <typename T> struct A { constexpr A () : a() {} [[no_unique_address]] T a; }; +template <unsigned long, typename...> struct B; +template <unsigned long T, typename U, typename... V> +struct B<T, U, V...> : B<1, V...>, A<U> {}; +template <unsigned long T, typename U> struct B<T, U> : A<U> {}; +template <typename... h> struct C : B<0, h...> {}; +struct D {}; +struct E { C<int, D> k; virtual ~E (); } a; |