public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alex Coplan <acoplan@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8951] c++: Don't advertise cxx_constexpr_string_builtins [PR113658]
Date: Tue, 13 Feb 2024 10:55:02 +0000 (GMT)	[thread overview]
Message-ID: <20240213105502.CBCCC3858410@sourceware.org> (raw)

https://gcc.gnu.org/g:0d810b7d133c72b7e62b294ffaaf131560ce2391

commit r14-8951-g0d810b7d133c72b7e62b294ffaaf131560ce2391
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Wed Jan 31 14:50:55 2024 +0000

    c++: Don't advertise cxx_constexpr_string_builtins [PR113658]
    
    When __has_feature was introduced for GCC 14, I included the feature
    cxx_constexpr_string_builtins, since of the relevant string builtins
    that GCC implements, it seems to support constexpr evaluation of those
    builtins.
    
    However, as the PR shows, GCC doesn't implement the full list of
    builtins in the clang documentation.  After enumerating the builtins,
    the clang docs [1] say:
    
    > Support for constant expression evaluation for the above builtins can
    > be detected with __has_feature(cxx_constexpr_string_builtins).
    
    and a strict reading of this would suggest we can't really support
    constexpr evaluation of a builtin if we don't implement the builtin in
    the first place.
    
    So the conservatively correct thing to do seems to be to stop
    advertising the feature altogether to avoid failing to build code which
    assumes the presence of this feature implies the presence of all the
    builtins listed in the clang documentation.
    
    [1] : https://clang.llvm.org/docs/LanguageExtensions.html#string-builtins
    
    gcc/cp/ChangeLog:
    
            PR c++/113658
            * cp-objcp-common.cc (cp_feature_table): Remove entry for
            cxx_constexpr_string_builtins.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/113658
            * g++.dg/ext/has-feature2.C: New test.

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

diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
index f06edf04ef07..85dde0459faa 100644
--- a/gcc/cp/cp-objcp-common.cc
+++ b/gcc/cp/cp-objcp-common.cc
@@ -110,7 +110,6 @@ static constexpr cp_feature_info cp_feature_table[] =
   { "cxx_alignof", cxx11 },
   { "cxx_attributes", cxx11 },
   { "cxx_constexpr", cxx11 },
-  { "cxx_constexpr_string_builtins", cxx11 },
   { "cxx_decltype", cxx11 },
   { "cxx_decltype_incomplete_return_types", cxx11 },
   { "cxx_default_function_template_args", cxx11 },
diff --git a/gcc/testsuite/g++.dg/ext/has-feature2.C b/gcc/testsuite/g++.dg/ext/has-feature2.C
new file mode 100644
index 000000000000..5f62916badf8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/has-feature2.C
@@ -0,0 +1,14 @@
+// { dg-do compile }
+// { dg-options "" }
+
+// PR c++/113658: we shouldn't declare support for
+// cxx_constexpr_string_builtins as GCC is missing some of the builtins
+// that clang implements.
+
+#if __has_feature (cxx_constexpr_string_builtins)
+#error
+#endif
+
+#if __has_extension (cxx_constexpr_string_builtins)
+#error
+#endif

                 reply	other threads:[~2024-02-13 10:55 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=20240213105502.CBCCC3858410@sourceware.org \
    --to=acoplan@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).