aboutsummaryrefslogtreecommitdiff
path: root/libcxx
diff options
context:
space:
mode:
authorNikolas Klauser <nikolasklauser@berlin.de>2024-03-09 01:09:28 +0100
committerGitHub <noreply@github.com>2024-03-09 01:09:28 +0100
commit4d323e404d43526ad8263769f00aace9db2e57c5 (patch)
treea8c4627b72e63557078ba961668ea863c7a38b49 /libcxx
parent624ea68cbc3ce422b3ee110c0c0af839eec2e278 (diff)
downloadllvm-4d323e404d43526ad8263769f00aace9db2e57c5.zip
llvm-4d323e404d43526ad8263769f00aace9db2e57c5.tar.gz
llvm-4d323e404d43526ad8263769f00aace9db2e57c5.tar.bz2
[libc++] Allow the use of extensions in the implementation (#79532)
We've talked about allowing extensions on [discourse](https://discourse.llvm.org/t/rfc-use-language-extensions-from-future-standards-in-libc/71898/5) and in a libc++ monthly meeting and agreed to test it out in the LLVM 18 release. We've done that with the `tuple` constructor overload set (using conditional `explicit`). Since we haven't heard about any breakages, it seems safe to do. This patch enables the use of extension from later C++ standards inside the versioned `std` namespaces. This should be good enough, since almost all of our code is inside that namespace. This approach also avoids the use of extensions inside the test `std` suite. That part of the code base should stay clean, since it's a test suite that is also used by other vendors to test their implementations.
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/include/__config61
-rw-r--r--libcxx/include/tuple6
2 files changed, 41 insertions, 26 deletions
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 3a438e8..11e13e0 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -406,6 +406,10 @@ _LIBCPP_HARDENING_MODE_DEBUG
# define __has_include(...) 0
# endif
+# ifndef __has_warning
+# define __has_warning(...) 0
+# endif
+
# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
# endif
@@ -723,6 +727,23 @@ typedef __char32_t char32_t;
# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
# endif
+# ifdef _LIBCPP_COMPILER_CLANG_BASED
+# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
+# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
+# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
+# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
+# elif defined(_LIBCPP_COMPILER_GCC)
+# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
+# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
+# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
+# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
+# else
+# define _LIBCPP_DIAGNOSTIC_PUSH
+# define _LIBCPP_DIAGNOSTIC_POP
+# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
+# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
+# endif
+
# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
# define _LIBCPP_HARDENING_SIG f
# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
@@ -810,16 +831,33 @@ typedef __char32_t char32_t;
# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
# endif
+// TODO: Remove this workaround once we drop support for Clang 16
+#if __has_warning("-Wc++23-extensions")
+# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
+#else
+# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions")
+#endif
+
// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
// clang-format off
-# define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
+# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_DIAGNOSTIC_PUSH \
+ _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \
+ _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
+ _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
+ _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
+ _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \
+ _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
+ _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
+ _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
+ _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") \
+ namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
inline namespace _LIBCPP_ABI_NAMESPACE {
-# define _LIBCPP_END_NAMESPACE_STD }}
+# define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_DIAGNOSTIC_POP
# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \
inline namespace __fs { namespace filesystem {
-# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
+# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
// clang-format on
# if __has_attribute(__enable_if__)
@@ -1256,23 +1294,6 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
// the ABI inconsistent.
# endif
-# ifdef _LIBCPP_COMPILER_CLANG_BASED
-# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
-# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
-# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
-# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
-# elif defined(_LIBCPP_COMPILER_GCC)
-# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
-# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
-# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
-# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
-# else
-# define _LIBCPP_DIAGNOSTIC_PUSH
-# define _LIBCPP_DIAGNOSTIC_POP
-# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
-# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
-# endif
-
// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
// functions is gradually being added to existing C libraries. The conditions
// below check for known C library versions and conditions under which these
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 0101d64..8808db6 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -548,10 +548,6 @@ class _LIBCPP_TEMPLATE_VIS tuple {
public:
// [tuple.cnstr]
- _LIBCPP_DIAGNOSTIC_PUSH
- _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions")
- _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions")
-
// tuple() constructors (including allocator_arg_t variants)
template <template <class...> class _IsImpDefault = __is_implicitly_default_constructible,
template <class...> class _IsDefault = is_default_constructible,
@@ -833,8 +829,6 @@ public:
: __base_(allocator_arg_t(), __alloc, std::move(__p)) {}
# endif // _LIBCPP_STD_VER >= 23
- _LIBCPP_DIAGNOSTIC_POP
-
// [tuple.assign]
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)