]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix [[no_unique_address]] and default mem-init [PR90432]
authorJason Merrill <jason@redhat.com>
Wed, 4 Mar 2020 22:30:58 +0000 (17:30 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 4 Mar 2020 22:33:10 +0000 (17:33 -0500)
output_constructor doesn't like two consecutive entries with fields at the
same position; let's avoid adding the one for the empty field.

gcc/cp/ChangeLog
2020-03-04  Jason Merrill  <jason@redhat.com>

PR c++/90432
* init.c (perform_member_init): Don't do aggregate initialization of
empty field.
* constexpr.c (cx_check_missing_mem_inits): Don't enforce
initialization of empty field.

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/cp/init.c
gcc/testsuite/g++.dg/cpp2a/no_unique_address3.C [new file with mode: 0644]

index da873dad1b5428f2013b5f56c1e305979de4cb81..80fb96ea9d3c6f18812bac9e9cdce2febbc0f24e 100644 (file)
@@ -1,3 +1,11 @@
+2020-03-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/90432
+       * init.c (perform_member_init): Don't do aggregate initialization of
+       empty field.
+       * constexpr.c (cx_check_missing_mem_inits): Don't enforce
+       initialization of empty field.
+
 2020-03-04  Jason Merrill  <jason@redhat.com>
 
        PR c++/90997
index 8fd5e4f2126ac23785f65989f2147ac60dde2318..b9b387ca7e9310905db00c54fb829c0d37679007 100644 (file)
@@ -821,6 +821,9 @@ cx_check_missing_mem_inits (tree ctype, tree body, bool complain)
                return true;
              continue;
            }
+         if (DECL_SIZE (field) && integer_zerop (DECL_SIZE (field)))
+           /* An empty field doesn't need an initializer.  */
+           continue;
          ftype = strip_array_types (TREE_TYPE (field));
          if (type_has_constexpr_default_constructor (ftype))
            {
index 6cd32d9844870927f8e2506a33a6f0e4b4900f95..44ddc8cd14471d6cadfee33250ecb5d5c3f22960 100644 (file)
@@ -860,6 +860,11 @@ perform_member_init (tree member, tree init)
        }
       if (init == error_mark_node)
        return;
+      if (DECL_SIZE (member) && integer_zerop (DECL_SIZE (member))
+         && !TREE_SIDE_EFFECTS (init))
+       /* Don't add trivial initialization of an empty base/field, as they
+          might not be ordered the way the back-end expects.  */
+       return;
       /* A FIELD_DECL doesn't really have a suitable lifetime, but
         make_temporary_var_for_ref_to_temp will treat it as automatic and
         set_up_extended_ref_temp wants to use the decl in a warning.  */
diff --git a/gcc/testsuite/g++.dg/cpp2a/no_unique_address3.C b/gcc/testsuite/g++.dg/cpp2a/no_unique_address3.C
new file mode 100644 (file)
index 0000000..07108b8
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/90432
+// { dg-do compile { target c++11 } }
+
+struct empty {};
+
+struct has_empty {
+  [[no_unique_address]] empty brace_or_equal_initialized{};
+};
+
+struct has_value {
+  int non_zero = 1;
+};
+
+struct pair : has_empty, has_value {};
+
+pair a;