https://gcc.gnu.org/g:c9e3181516f1c0786f81b9c813581bf986a6300a
commit r15-9664-gc9e3181516f1c0786f81b9c813581bf986a6300a Author: Jason Merrill <ja...@redhat.com> Date: Mon May 12 11:53:03 2025 -0400 c+: -Wabi false positive [PR120012] 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. (cherry picked from commit b4b4dfbd22e06877052bd4cc4b191d9d138155cf) Diff: --- gcc/cp/class.cc | 6 ++++-- gcc/testsuite/g++.dg/abi/base-defaulted2.C | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index 6767ac10358b..93ad9d6fd0b6 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -6835,8 +6835,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 index 000000000000..9652ae60c037 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/base-defaulted2.C @@ -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" } +};