public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-8729] c++: __has_builtin gives the wrong answer [PR106759]
Date: Tue, 30 Aug 2022 14:05:33 +0000 (GMT)	[thread overview]
Message-ID: <20220830140533.42BD83839042@sourceware.org> (raw)

https://gcc.gnu.org/g:29dfe1cacadd2a47b4e5b1cab11bd7263fe211c9

commit r12-8729-g29dfe1cacadd2a47b4e5b1cab11bd7263fe211c9
Author: Marek Polacek <polacek@redhat.com>
Date:   Mon Aug 29 16:54:05 2022 -0400

    c++: __has_builtin gives the wrong answer [PR106759]
    
    We've supported __is_nothrow_constructible since r11-4386, but
    names_builtin_p didn't know about it, so it gave the wrong answer for
     #if __has_builtin(__is_nothrow_constructible)
     ...
     #endif
    
    I've tested all C++-only built-ins and only two were missing.
    
            PR c++/106759
    
    gcc/cp/ChangeLog:
    
            * cp-objcp-common.cc (names_builtin_p): Handle RID_IS_NOTHROW_ASSIGNABLE
            and RID_IS_NOTHROW_CONSTRUCTIBLE.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/ext/has-builtin-1.C: New test.
    
    (cherry picked from commit fe915f35b7d8dc768a2b977c09aa02f933e1d1e9)

Diff:
---
 gcc/cp/cp-objcp-common.cc                |   2 +
 gcc/testsuite/g++.dg/ext/has-builtin-1.C | 127 +++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+)

diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
index 0b70d5567e4..f40fd588176 100644
--- a/gcc/cp/cp-objcp-common.cc
+++ b/gcc/cp/cp-objcp-common.cc
@@ -460,6 +460,8 @@ names_builtin_p (const char *name)
     case RID_IS_UNION:
     case RID_IS_ASSIGNABLE:
     case RID_IS_CONSTRUCTIBLE:
+    case RID_IS_NOTHROW_ASSIGNABLE:
+    case RID_IS_NOTHROW_CONSTRUCTIBLE:
     case RID_UNDERLYING_TYPE:
       return true;
     default:
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
new file mode 100644
index 00000000000..d89994c30e0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -0,0 +1,127 @@
+// PR c++/106759
+// { dg-do compile }
+// Verify that __has_builtin gives the correct answer for C++ built-ins.
+
+#if !__has_builtin (__builtin_addressof)
+# error "__has_builtin (__builtin_addressof) failed"
+#endif
+#if !__has_builtin (__builtin_bit_cast)
+# error "__has_builtin (__builtin_bit_cast) failed"
+#endif
+#if !__has_builtin (__builtin_launder)
+# error "__has_builtin (__builtin_launder) failed"
+#endif
+#if !__has_builtin (__has_nothrow_assign)
+# error "__has_builtin (__has_nothrow_assign) failed"
+#endif
+#if !__has_builtin (__has_nothrow_constructor)
+# error "__has_builtin (__has_nothrow_constructor) failed"
+#endif
+#if !__has_builtin (__has_nothrow_copy)
+# error "__has_builtin (__has_nothrow_copy) failed"
+#endif
+#if !__has_builtin (__has_trivial_assign)
+# error "__has_builtin (__has_trivial_assign) failed"
+#endif
+#if !__has_builtin (__has_trivial_constructor)
+# error "__has_builtin (__has_trivial_constructor) failed"
+#endif
+#if !__has_builtin (__has_trivial_copy)
+# error "__has_builtin (__has_trivial_copy) failed"
+#endif
+#if !__has_builtin (__has_trivial_destructor)
+# error "__has_builtin (__has_trivial_destructor) failed"
+#endif
+#if !__has_builtin (__has_unique_object_representations)
+# error "__has_builtin (__has_unique_object_representations) failed"
+#endif
+#if !__has_builtin (__has_virtual_destructor)
+# error "__has_builtin (__has_virtual_destructor) failed"
+#endif
+#if !__has_builtin (__is_abstract)
+# error "__has_builtin (__is_abstract) failed"
+#endif
+#if !__has_builtin (__is_aggregate)
+# error "__has_builtin (__is_aggregate) failed"
+#endif
+#if !__has_builtin (__is_base_of)
+# error "__has_builtin (__is_base_of) failed"
+#endif
+#if !__has_builtin (__is_class)
+# error "__has_builtin (__is_class) failed"
+#endif
+#if !__has_builtin (__is_empty)
+# error "__has_builtin (__is_empty) failed"
+#endif
+#if !__has_builtin (__is_enum)
+# error "__has_builtin (__is_enum) failed"
+#endif
+#if !__has_builtin (__is_final)
+# error "__has_builtin (__is_final) failed"
+#endif
+#if !__has_builtin (__is_layout_compatible)
+# error "__has_builtin (__is_layout_compatible) failed"
+#endif
+#if !__has_builtin (__is_literal_type)
+# error "__has_builtin (__is_literal_type) failed"
+#endif
+#if !__has_builtin (__is_pointer_interconvertible_base_of)
+# error "__has_builtin (__is_pointer_interconvertible_base_of) failed"
+#endif
+#if !__has_builtin (__is_pod)
+# error "__has_builtin (__is_pod) failed"
+#endif
+#if !__has_builtin (__is_polymorphic)
+# error "__has_builtin (__is_polymorphic) failed"
+#endif
+#if !__has_builtin (__is_same)
+# error "__has_builtin (__is_same) failed"
+#endif
+#if !__has_builtin (__is_same_as)
+# error "__has_builtin (__is_same_as) failed"
+#endif
+#if !__has_builtin (__is_standard_layout)
+# error "__has_builtin (__is_standard_layout) failed"
+#endif
+#if !__has_builtin (__is_trivial)
+# error "__has_builtin (__is_trivial) failed"
+#endif
+#if !__has_builtin (__is_trivially_assignable)
+# error "__has_builtin (__is_trivially_assignable) failed"
+#endif
+#if !__has_builtin (__is_trivially_constructible)
+# error "__has_builtin (__is_trivially_constructible) failed"
+#endif
+#if !__has_builtin (__is_trivially_copyable)
+# error "__has_builtin (__is_trivially_copyable) failed"
+#endif
+#if !__has_builtin (__is_union)
+# error "__has_builtin (__is_union) failed"
+#endif
+#if !__has_builtin (__underlying_type)
+# error "__has_builtin (__underlying_type) failed"
+#endif
+#if !__has_builtin (__is_assignable)
+# error "__has_builtin (__is_assignable) failed"
+#endif
+#if !__has_builtin (__is_constructible)
+# error "__has_builtin (__is_constructible) failed"
+#endif
+#if !__has_builtin (__is_nothrow_assignable)
+# error "__has_builtin (__is_nothrow_assignable) failed"
+#endif
+#if !__has_builtin (__is_nothrow_constructible)
+# error "__has_builtin (__is_nothrow_constructible) failed"
+#endif
+#if !__has_builtin (__builtin_is_constant_evaluated)
+# error "__has_builtin (__builtin_is_constant_evaluated) failed"
+#endif
+#if !__has_builtin (__builtin_source_location)
+# error "__has_builtin (__builtin_source_location) failed"
+#endif
+#if !__has_builtin (__builtin_is_corresponding_member)
+# error "__has_builtin (__builtin_is_corresponding_member) failed"
+#endif
+#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class)
+# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed"
+#endif

                 reply	other threads:[~2022-08-30 14:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220830140533.42BD83839042@sourceware.org \
    --to=mpolacek@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).