My second patch for 97566 omits nested CONSTRUCTORs for empty fields, but we
do want them for empty union members.
gcc/cp/ChangeLog:
PR c++/98994
PR c++/97566
* constexpr.c (cxx_eval_store_expression): Only skip empty fields in
RECORD_TYPE.
gcc/testsuite/ChangeLog:
PR c++/98994
* g++.dg/cpp2a/no_unique_address12.C: New test.
type = refs->pop();
tree index = refs->pop();
- if (is_empty_field (index))
+ if (code == RECORD_TYPE && is_empty_field (index))
/* Don't build a sub-CONSTRUCTOR for an empty base or field, as they
have no data and might have an offset lower than previously declared
fields, which confuses the middle-end. The code below will notice
--- /dev/null
+// PR c++/98994
+// { dg-do compile { target c++20 } }
+
+struct empty {};
+
+union U {
+ constexpr U(): a() { }
+
+ [[no_unique_address]] empty a;
+};
+
+constexpr U u;