]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c+: -Wabi false positive [PR120012]
authorJason Merrill <jason@redhat.com>
Mon, 12 May 2025 15:53:03 +0000 (11:53 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 12 May 2025 19:43:03 +0000 (15:43 -0400)
The warning compares the position of a field depending on whether or not the
previous base/field is considered a POD for layout, but failed to consider
whether the previous base/field is empty; layout of an empty base doesn't
consider PODness.

PR c++/120012

gcc/cp/ChangeLog:

* class.cc (check_non_pod_aggregate): Check is_empty_class.

gcc/testsuite/ChangeLog:

* g++.dg/abi/base-defaulted2.C: New test.

gcc/cp/class.cc
gcc/testsuite/g++.dg/abi/base-defaulted2.C [new file with mode: 0644]

index 2764bb52ddd0e5aa4871758556707133098f20c3..db39e579870c44f0c5b13c446470f9f01455d579 100644 (file)
@@ -6879,8 +6879,10 @@ check_non_pod_aggregate (tree field)
   tree type = TREE_TYPE (field);
   if (TYPE_IDENTIFIER (type) == as_base_identifier)
     type = TYPE_CONTEXT (type);
-  if (!CLASS_TYPE_P (type) || (!CLASSTYPE_NON_POD_AGGREGATE (type)
-                              && !CLASSTYPE_NON_AGGREGATE_POD (type)))
+  if (!CLASS_TYPE_P (type)
+      || is_empty_class (type)
+      || (!CLASSTYPE_NON_POD_AGGREGATE (type)
+         && !CLASSTYPE_NON_AGGREGATE_POD (type)))
     return;
   tree size = end_of_class (type, (DECL_FIELD_IS_BASE (field)
                                   ? eoc_nvsize : eoc_nv_or_dsize));
diff --git a/gcc/testsuite/g++.dg/abi/base-defaulted2.C b/gcc/testsuite/g++.dg/abi/base-defaulted2.C
new file mode 100644 (file)
index 0000000..9652ae6
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fabi-version=20 -Wabi" }
+
+struct Base {
+protected:
+  Base() = default;
+  ~Base() = default;
+};
+
+struct Derived : Base {
+  void* ptr;                   // { dg-bogus "offset" }
+};