public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Don't advertise cxx_constexpr_string_builtins [PR113658]
@ 2024-02-02 10:27 Alex Coplan
  2024-02-02 14:34 ` Marek Polacek
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Coplan @ 2024-02-02 10:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill, Nathan Sidwell

[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]

Bootstrapped/regtested on x86_64-apple-darwin, OK for trunk?

Thanks,
Alex

-- >8 --

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/pr113658.C: New test.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1059 bytes --]

diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
index f06edf04ef0..85dde0459fa 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/pr113658.C b/gcc/testsuite/g++.dg/ext/pr113658.C
new file mode 100644
index 00000000000..f4a34888f28
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/pr113658.C
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "" }
+
+// PR113658: 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-09 17:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02 10:27 [PATCH] c++: Don't advertise cxx_constexpr_string_builtins [PR113658] Alex Coplan
2024-02-02 14:34 ` Marek Polacek
2024-02-02 15:45   ` Alex Coplan
2024-02-02 16:27     ` Marek Polacek
2024-02-02 16:32       ` Jakub Jelinek
2024-02-02 16:37         ` Marek Polacek
2024-02-09 17:55     ` Jason Merrill

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).