[libcxx-commits] [libcxxabi] [libcxx] [libc++] Bump the C++ Standard used to compile the dylib to C++23 (PR #66824)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 3 08:12:57 PDT 2023


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/66824

>From cb19cef71b340a7af7f77851872298faddb54d0e Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 19 Sep 2023 17:16:49 -0400
Subject: [PATCH 1/3] [libc++] Bump the C++ Standard used to compile the dylib
 to C++23

This is necessary in order to implement some papers like P2467R1, which
require using C++23 declarations in the dylib. It is a good habit to keep
building the dylib with a recent standard version regardless.
---
 libcxx/CMakeLists.txt                              | 5 ++---
 libcxx/src/include/sso_allocator.h                 | 3 ++-
 libcxx/src/locale.cpp                              | 7 ++++---
 libcxx/test/tools/clang_tidy_checks/CMakeLists.txt | 4 ++--
 libcxxabi/src/CMakeLists.txt                       | 4 ++--
 5 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index d03421afde1e755..e031192043a3576 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -504,10 +504,9 @@ remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
 # Required flags ==============================================================
 function(cxx_add_basic_build_flags target)
 
-  # Require C++20 for all targets. C++17 is needed to use aligned allocation
-  # in the dylib. C++20 is needed to use char8_t.
+  # Require C++23 for all targets.
   set_target_properties(${target} PROPERTIES
-    CXX_STANDARD 20
+    CXX_STANDARD 23
     CXX_STANDARD_REQUIRED YES
     CXX_EXTENSIONS NO)
 
diff --git a/libcxx/src/include/sso_allocator.h b/libcxx/src/include/sso_allocator.h
index 6a682fc43f86fc5..0cc8738815ddd46 100644
--- a/libcxx/src/include/sso_allocator.h
+++ b/libcxx/src/include/sso_allocator.h
@@ -11,6 +11,7 @@
 #define _LIBCPP_SSO_ALLOCATOR_H
 
 #include <__config>
+#include <cstddef>
 #include <memory>
 #include <new>
 #include <type_traits>
@@ -34,7 +35,7 @@ class _LIBCPP_HIDDEN __sso_allocator<void, _Np>
 template <class _Tp, size_t _Np>
 class _LIBCPP_HIDDEN __sso_allocator
 {
-    typename aligned_storage<sizeof(_Tp) * _Np>::type buf_;
+    alignas(_Tp) std::byte buf_[sizeof(_Tp) * _Np];
     bool __allocated_;
 public:
     typedef size_t            size_type;
diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp
index 317b4dec7d241e5..c37e091dcc4671b 100644
--- a/libcxx/src/locale.cpp
+++ b/libcxx/src/locale.cpp
@@ -10,6 +10,7 @@
 #include <algorithm>
 #include <clocale>
 #include <codecvt>
+#include <cstddef>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
@@ -87,7 +88,7 @@ struct release
 template <class T, class ...Args>
 T& make(Args ...args)
 {
-    static typename aligned_storage<sizeof(T)>::type buf;
+    alignas(T) static std::byte buf[sizeof(T)];
     auto *obj = ::new (&buf) T(args...);
     return *obj;
 }
@@ -541,7 +542,7 @@ const locale&
 locale::__imp::make_classic()
 {
     // only one thread can get in here and it only gets in once
-    static aligned_storage<sizeof(locale)>::type buf;
+    alignas(locale) static std::byte buf[sizeof(locale)];
     locale* c = reinterpret_cast<locale*>(&buf);
     c->__locale_ = &make<__imp>(1u);
     return *c;
@@ -558,7 +559,7 @@ locale&
 locale::__imp::make_global()
 {
     // only one thread can get in here and it only gets in once
-    static aligned_storage<sizeof(locale)>::type buf;
+    alignas(locale) static std::byte buf[sizeof(locale)];
     auto *obj = ::new (&buf) locale(locale::classic());
     return *obj;
 }
diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 260e90f45f577cb..8f98d4e40d27065 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -33,7 +33,7 @@ set(Clang_DIR "${Clang_DIR_SAVE}" CACHE PATH "The directory containing a CMake c
 
 message(STATUS "Found system-installed LLVM ${LLVM_PACKAGE_VERSION} with headers in ${LLVM_INCLUDE_DIRS}")
 
-set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_CXX_STANDARD 23)
 
 # Link only against clangTidy itself, not anything that clangTidy uses; otherwise we run setup code multiple times
 # which results in clang-tidy crashing
@@ -58,7 +58,7 @@ add_library(cxx-tidy MODULE ${SOURCES})
 target_link_libraries(cxx-tidy clangTidy)
 
 set_target_properties(cxx-tidy PROPERTIES
-                      CXX_STANDARD 20
+                      CXX_STANDARD 23
                       CXX_STANDARD_REQUIRED YES
                       CXX_EXTENSIONS NO)
 
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 06a9a5fa91d9454..aec97104fffae46 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -171,7 +171,7 @@ target_link_libraries(cxxabi_shared_objects PUBLIC cxxabi-headers)
 set_target_properties(cxxabi_shared_objects
   PROPERTIES
     CXX_EXTENSIONS OFF
-    CXX_STANDARD 20
+    CXX_STANDARD 23
     CXX_STANDARD_REQUIRED OFF
     COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
     DEFINE_SYMBOL ""
@@ -251,7 +251,7 @@ target_link_libraries(cxxabi_static_objects PUBLIC cxxabi-headers)
 set_target_properties(cxxabi_static_objects
   PROPERTIES
     CXX_EXTENSIONS OFF
-    CXX_STANDARD 20
+    CXX_STANDARD 23
     CXX_STANDARD_REQUIRED OFF
     COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
 )

>From 771ee197c8a972a579ae5ab56b9f2516ce4b6fba Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 3 Nov 2023 10:43:45 -0400
Subject: [PATCH 2/3] Build clang-tidy with C++20

---
 libcxx/test/tools/clang_tidy_checks/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 8f98d4e40d27065..260e90f45f577cb 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -33,7 +33,7 @@ set(Clang_DIR "${Clang_DIR_SAVE}" CACHE PATH "The directory containing a CMake c
 
 message(STATUS "Found system-installed LLVM ${LLVM_PACKAGE_VERSION} with headers in ${LLVM_INCLUDE_DIRS}")
 
-set(CMAKE_CXX_STANDARD 23)
+set(CMAKE_CXX_STANDARD 20)
 
 # Link only against clangTidy itself, not anything that clangTidy uses; otherwise we run setup code multiple times
 # which results in clang-tidy crashing
@@ -58,7 +58,7 @@ add_library(cxx-tidy MODULE ${SOURCES})
 target_link_libraries(cxx-tidy clangTidy)
 
 set_target_properties(cxx-tidy PROPERTIES
-                      CXX_STANDARD 23
+                      CXX_STANDARD 20
                       CXX_STANDARD_REQUIRED YES
                       CXX_EXTENSIONS NO)
 

>From ac734df3e0442f1c63b38b7a1f93f9015c69c370 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 3 Nov 2023 11:09:25 -0400
Subject: [PATCH 3/3] Don't strictly enforce C++23 when building the dylib

---
 libcxx/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index e031192043a3576..4c30b59a84f5303 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -504,10 +504,10 @@ remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
 # Required flags ==============================================================
 function(cxx_add_basic_build_flags target)
 
-  # Require C++23 for all targets.
+  # Use C++23 for all targets.
   set_target_properties(${target} PROPERTIES
     CXX_STANDARD 23
-    CXX_STANDARD_REQUIRED YES
+    CXX_STANDARD_REQUIRED NO
     CXX_EXTENSIONS NO)
 
   # When building the dylib, don't warn for unavailable aligned allocation



More information about the libcxx-commits mailing list