]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Don't advertise __has_cpp_attribute (gnu::trivial_abi)
authorJakub Jelinek <jakub@redhat.com>
Fri, 10 Jul 2026 07:13:37 +0000 (09:13 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 10 Jul 2026 07:13:37 +0000 (09:13 +0200)
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  <jakub@redhat.com>

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 <jason@redhat.com>
gcc/c-family/c-lex.cc
gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi8.C [new file with mode: 0644]

index 334ab3bf4e4cb641afaffb50b8c556b42a4d3f3f..3f3e9f30aa4ec578855477bd4257c35d069fd6b7 100644 (file)
@@ -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 (file)
index 0000000..48331ab
--- /dev/null
@@ -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