[libcxx-commits] [libcxx] [libc++] Build the library with C++26 (PR #181021)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 25 06:23:25 PST 2026


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

>From ebcbb0b89d9ba5e4efa84c62b8ae8764f2f4a2f4 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 11 Feb 2026 16:25:04 -0500
Subject: [PATCH 1/6] [libc++] Build the library with C++26

All supported compilers support C++26. This allows simplifying some
of the upcoming <text_encoding> implementation.
---
 libcxx/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 0ac582cb561a8..8f3f08fb60de2 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -504,9 +504,9 @@ remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
 # Required flags ==============================================================
 function(cxx_add_basic_build_flags target)
 
-  # Use C++23 for all targets.
+  # Use C++26 for all targets.
   set_target_properties(${target} PROPERTIES
-    CXX_STANDARD 23
+    CXX_STANDARD 26
     CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
     CXX_EXTENSIONS NO)
 

>From 22d14f2e018b8b0d4af1859532b4f57cbda8918b Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 23 Feb 2026 11:48:13 -0500
Subject: [PATCH 2/6] Don't use set_target_properties to remove dependency on
 recent CMake

---
 libcxx/CMakeLists.txt | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 8f3f08fb60de2..dcb393b380a7c 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -504,11 +504,9 @@ remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
 # Required flags ==============================================================
 function(cxx_add_basic_build_flags target)
 
-  # Use C++26 for all targets.
-  set_target_properties(${target} PROPERTIES
-    CXX_STANDARD 26
-    CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
-    CXX_EXTENSIONS NO)
+  # Use C++26 for all targets. Note that we don't use CXX_STANDARD or cxx_std_foo
+  # since that requires a newer CMake than is available.
+  target_compile_options(${target} PRIVATE -std=c++26)
 
   # When building the dylib, don't warn for unavailable aligned allocation
   # functions based on the deployment target -- they are always available

>From 59db63d44a380e19588f295464b1476fdc59ce63 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 23 Feb 2026 12:43:22 -0500
Subject: [PATCH 3/6] Handle MSVC

---
 libcxx/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index dcb393b380a7c..b9bf2d8b9922c 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -506,7 +506,7 @@ function(cxx_add_basic_build_flags target)
 
   # Use C++26 for all targets. Note that we don't use CXX_STANDARD or cxx_std_foo
   # since that requires a newer CMake than is available.
-  target_compile_options(${target} PRIVATE -std=c++26)
+  target_compile_options(${target} PRIVATE $<IF:$<CXX_COMPILER_ID:MSVC>,/std:c++26,-std=c++26>)
 
   # When building the dylib, don't warn for unavailable aligned allocation
   # functions based on the deployment target -- they are always available

>From 4b492492b2ea6ec675cb1f7cf45e153959f7ccc8 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 25 Feb 2026 08:24:25 -0500
Subject: [PATCH 4/6] Try fixing clang-cl invocations

---
 libcxx/CMakeLists.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index b9bf2d8b9922c..e9049a3fd0eb2 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -506,7 +506,11 @@ function(cxx_add_basic_build_flags target)
 
   # Use C++26 for all targets. Note that we don't use CXX_STANDARD or cxx_std_foo
   # since that requires a newer CMake than is available.
-  target_compile_options(${target} PRIVATE $<IF:$<CXX_COMPILER_ID:MSVC>,/std:c++26,-std=c++26>)
+  if (LIBCXX_TARGETING_CLANG_CL)
+    target_compile_options(${target} PRIVATE /std:c++latest)
+  else()
+    target_compile_options(${target} PRIVATE -std=c++26)
+  endif()
 
   # When building the dylib, don't warn for unavailable aligned allocation
   # functions based on the deployment target -- they are always available

>From ad33ee32dae33b57ee1f4569048631132338e32a Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 25 Feb 2026 09:20:44 -0500
Subject: [PATCH 5/6] Try fixing bootstrapping build

---
 libcxx/CMakeLists.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index e9049a3fd0eb2..dec3e3600c755 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -4,6 +4,12 @@
 cmake_minimum_required(VERSION 3.20.0)
 set(LLVM_SUBPROJECT_TITLE "libc++")
 
+# Unset the C++ Standard: other projects sometimes override this global property, which
+# is incompatible with libc++ (since we set our own standard via other means).
+# TODO: Figure out which other part of the build is setting this and resolve the issue
+#       at the root.
+unset(CMAKE_CXX_STANDARD)
+
 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
 
 # Add path for custom modules

>From 2e5e6a86fd2aad38b3b765b9b811d7153d452cb1 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 25 Feb 2026 09:23:04 -0500
Subject: [PATCH 6/6] Also drop CMAKE_CXX_STANDARD from clang tidy: this is
 already handled via a target property

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

diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 521a60c0fc498..3663575e33e55 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -25,8 +25,6 @@ endif()
 
 message(STATUS "Found system-installed LLVM ${LLVM_PACKAGE_VERSION} with headers in ${LLVM_INCLUDE_DIRS}")
 
-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
 set_target_properties(clangTidy PROPERTIES INTERFACE_LINK_LIBRARIES "")



More information about the libcxx-commits mailing list