Hi! In r11-6895 handling of empty bases has been fixed such that non-lval stores of empty classes are not added when the type of *valp doesn't match the type of the initializer, but as this testcase shows it is done only when *valp is non-NULL. If it is NULL, we still shouldn't add empty class constructors if the type of the constructor elt *valp points to doesn't match.
Bootstrapped/regtested on x86_64-linux and i686-linux, tested also by Liu Hao on 10 branch, preapproved by Jason in the PR, committed to trunk. 2021-04-16 Jakub Jelinek <ja...@redhat.com> PR c++/100111 * constexpr.c (cxx_eval_store_expression): Don't add CONSTRUCTORs for empty classes into *valp when types don't match even when *valp is NULL. * g++.dg/cpp0x/constexpr-100111.C: New test. --- gcc/cp/constexpr.c.jj 2021-04-08 17:19:12.235414181 +0200 +++ gcc/cp/constexpr.c 2021-04-16 11:06:27.138019389 +0200 @@ -5518,6 +5518,14 @@ cxx_eval_store_expression (const constex CONSTRUCTOR_NO_CLEARING (*valp) = CONSTRUCTOR_NO_CLEARING (init); } + else if (TREE_CODE (init) == CONSTRUCTOR + && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (init), + type)) + { + /* See above on initialization of empty bases. */ + gcc_assert (is_empty_class (TREE_TYPE (init)) && !lval); + return init; + } else *valp = init; --- gcc/testsuite/g++.dg/cpp0x/constexpr-100111.C.jj 2021-04-16 11:33:20.193882609 +0200 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-100111.C 2021-04-16 11:32:46.039266786 +0200 @@ -0,0 +1,7 @@ +// PR c++/100111 +// { dg-do compile { target c++11 } } +// { dg-options "-fno-elide-constructors" } + +struct A {}; +struct B : A { int b; constexpr B (A x) : A(x), b() {} }; +struct C { B c; constexpr C () : c({}) {} } d; Jakub