https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124957
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Patrick Palka <[email protected]>: https://gcc.gnu.org/g:6112538b060d8a973500a3ae5e930545b422600f commit r17-338-g6112538b060d8a973500a3ae5e930545b422600f Author: Patrick Palka <[email protected]> Date: Tue May 5 11:26:16 2026 -0400 c++/modules: false positive abi_tag mismatch [PR124957] Here x in _a.C is defined in terms of A, which has an abi_tag, so it should inherit A's abi_tag. It turns out this abi_tag propagation happens only during mangling via class.cc:check_abi_tags, and we happen to never mangle x in this TU, so we stream out x with no abi_tag. In _b.C we import and re-export x, and we also happen to mangle x (for arbitrary reasons that I didn't question), which means when we stream it out this time it has an abi_tag. In _c.C we import both versions of x, merge them, during which we compare their abi_tag, notice a mismatch, and diagnose. But the mismatch is solely due to one version ('existing') being mangled, and therefore went through class.cc:check_abi_tags, and the other ('decl') not. Idiosyncracies of this testcase aside (like why x gets mangled in _b.C, why we stream in two apparent x's in _c.C), it does seem like this diagnostic routine should be robust to this situation. To that end this patch makes the routine ignore such inherited tags during the comparison if there's a mangled-ness mismatch, via a new flag ABI_TAG_INHERITED that's set on all inherited tags. In passing, rename the existing flag ABI_TAG_IMPLICIT to ABI_TAG_NOT_MANGLED to better describe and differentiate it from the new flag. PR c++/124957 gcc/cp/ChangeLog: * class.cc (check_tag): Set ABI_TAG_INHERITED on the TREE_LIST of an inherited tag. Adjust after ABI_TAG_IMPLICIT renaming. * cp-tree.h (ABI_TAG_IMPLICIT): Rename to ... (ABI_TAG_NOT_MANGLED): ... this. (equal_abi_tags): Adjust forward declaration. * mangle.cc (write_unqualified_name): Adjust equal_abi_tags call. (sorted_abi_tags): New ignore_inherited_p parameter, for ignoring ABI_TAG_INHERITED tags. Adjust after ABI_TAG_INHERITED renaming. (write_abi_tags): Adjust sorted_abi_tags call. (equal_abi_tags): New ignore_inherited_p parameter. Pass it to sorted_abi_tags. * module.cc (trees_in::check_abi_tags): Pass ignore_inherited_p=true to equal_abi_tags iff there's a mangled-ness mismatch. gcc/testsuite/ChangeLog: * g++.dg/modules/attrib-6_a.C: New test. * g++.dg/modules/attrib-6_b.C: New test. * g++.dg/modules/attrib-6_c.C: New test. Reviewed-by: Jason Merrill <[email protected]>
