On 7/8/26 12:55 PM, Jakub Jelinek wrote:
Hi!
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)).
Lightly tested so far, ok for trunk if it passes full
bootstrap/regtest?
2026-07-08 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.
--- gcc/c-family/c-lex.cc.jj 2026-04-28 08:54:25.377643162 +0200
+++ gcc/c-family/c-lex.cc 2026-07-08 18:47:10.790872988 +0200
@@ -403,6 +403,13 @@ c_common_has_attribute (cpp_reader *pfil
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);
}
--- gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi8.C.jj 2026-07-08
18:49:01.145455196 +0200
+++ gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi8.C 2026-07-08
18:49:23.583166926 +0200
@@ -0,0 +1,20 @@
+// { dg-do compile { 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) != 1
+#error
+#endif
This answer seems clearly wrong, since [[trivial_abi]] doesn't work.
I'd prefer expecting 0 and xfail.
+#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
Jakub