https://gcc.gnu.org/g:619b1f8b85d54930c17c608698658ac7cd45e5f1
commit r17-2300-g619b1f8b85d54930c17c608698658ac7cd45e5f1 Author: Jakub Jelinek <[email protected]> Date: Fri Jul 10 09:13:37 2026 +0200 c++: Don't advertise __has_cpp_attribute (gnu::trivial_abi) I've noticed we advertise __has_cpp_attribute (gnu::trivial_abi) and __has_attribute (gnu::trivial_abi). It is true we have gnu::trivial_abi in the tables, but solely to give errors on those when using the gnu:: scope and to suggest [[clang::trivial_abi]] or __attribute__((trivial_abi)). 2026-07-10 Jakub Jelinek <[email protected]> PR c++/107187 * c-lex.cc (c_common_has_attribute): Don't advertise __has_cpp_attribute (gnu::trivial_abi) in C++. * g++.dg/cpp0x/attr-trivial_abi8.C: New test. Reviewed-by: Jason Merrill <[email protected]> Diff: --- gcc/c-family/c-lex.cc | 7 +++++++ gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi8.C | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc index 334ab3bf4e4c..3f3e9f30aa4e 100644 --- a/gcc/c-family/c-lex.cc +++ b/gcc/c-family/c-lex.cc @@ -403,6 +403,13 @@ c_common_has_attribute (cpp_reader *pfile, bool std_syntax) result = 1; if (result) attr_name = NULL_TREE; + /* gnu::trivial_abi is in the attribute table just + to error on it and suggest using [[clang::trivial_abi]] + or __attribute__((trivial_abi)). Don't advertise it. */ + else if (c_dialect_cxx () + && is_attribute_p ("gnu", attr_ns) + && is_attribute_p ("trivial_abi", attr_id)) + attr_name = NULL_TREE; else attr_name = build_tree_list (attr_ns, attr_id); } diff --git a/gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi8.C b/gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi8.C new file mode 100644 index 000000000000..48331ab5adaf --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi8.C @@ -0,0 +1,21 @@ +// { dg-do preprocess { target c++11 } } + +#if __has_cpp_attribute (clang::trivial_abi) != 1 +#error +#endif +#if __has_cpp_attribute (gnu::trivial_abi) != 0 +#error +#endif +#if __has_cpp_attribute (trivial_abi) != 0 +#error This fails for now +// { dg-bogus "This fails for now" "" { xfail *-*-* } .-1 } +#endif +#if __has_attribute (clang::trivial_abi) != 1 +#error +#endif +#if __has_attribute (gnu::trivial_abi) != 0 +#error +#endif +#if __has_attribute (trivial_abi) != 1 +#error +#endif
