[gcc/devel/omp/gcc-9] c++: Fix [[no_unique_address]] and default mem-init [PR90432]
Tobias Burnus
burnus@gcc.gnu.org
Thu Mar 5 14:58:00 GMT 2020
https://gcc.gnu.org/g:9af9e004831f8efdfb68c2affea07b17fadd3279
commit 9af9e004831f8efdfb68c2affea07b17fadd3279
Author: Jason Merrill <jason@redhat.com>
Date: Wed Mar 4 17:30:58 2020 -0500
c++: Fix [[no_unique_address]] and default mem-init [PR90432]
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.
Diff:
---
gcc/cp/ChangeLog | 8 ++++++++
gcc/cp/constexpr.c | 3 +++
gcc/cp/init.c | 5 +++++
gcc/testsuite/g++.dg/cpp2a/no_unique_address3.C | 16 ++++++++++++++++
4 files changed, 32 insertions(+)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index da873da..80fb96e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,13 @@
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
* semantics.c (finish_call_expr): Don't call
instantiate_non_dependent_expr before warn_for_memset.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 8fd5e4f..b9b387c 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -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))
{
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 6cd32d9..44ddc8c 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -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
index 0000000..07108b8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/no_unique_address3.C
@@ -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;
More information about the Gcc-cvs
mailing list