[libcxx-commits] [libcxx] b9f2403 - [libc++][C++20 modules] Enabling in C++20.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 5 09:11:01 PDT 2023


Author: Mark de Wever
Date: 2023-09-05T18:10:46+02:00
New Revision: b9f24033f7f2d3485fbabbc56e3b31b5bc90e874

URL: https://github.com/llvm/llvm-project/commit/b9f24033f7f2d3485fbabbc56e3b31b5bc90e874
DIFF: https://github.com/llvm/llvm-project/commit/b9f24033f7f2d3485fbabbc56e3b31b5bc90e874.diff

LOG: [libc++][C++20 modules] Enabling in C++20.

The vendors of the MSVC STL, libstdc++ and libc++ have agreed [1] to
make the C++23 modules std and std.compat available in C++20. This
provides the std module; libc++ has not implemented the std.compat
module yet.

[1] https://github.com/microsoft/STL/issues/3945

Depends on D158357

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D158358

Added: 
    

Modified: 
    libcxx/docs/Modules.rst
    libcxx/docs/UsingLibcxx.rst
    libcxx/modules/std/algorithm.inc
    libcxx/modules/std/bit.inc
    libcxx/modules/std/expected.inc
    libcxx/modules/std/format.inc
    libcxx/modules/std/functional.inc
    libcxx/modules/std/mdspan.inc
    libcxx/modules/std/memory.inc
    libcxx/modules/std/print.inc
    libcxx/modules/std/ranges.inc
    libcxx/modules/std/string.inc
    libcxx/modules/std/thread.inc
    libcxx/modules/std/tuple.inc
    libcxx/modules/std/type_traits.inc
    libcxx/modules/std/utility.inc
    libcxx/modules/std/vector.inc
    libcxx/test/libcxx/module_std.gen.py
    libcxx/test/lit.local.cfg
    libcxx/utils/ci/buildkite-pipeline.yml

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/Modules.rst b/libcxx/docs/Modules.rst
index f7c4ea9412baadf..85c42af5a62b8db 100644
--- a/libcxx/docs/Modules.rst
+++ b/libcxx/docs/Modules.rst
@@ -49,10 +49,13 @@ What works
    * ``LIBCXX_ENABLE_RANDOM_DEVICE``
    * ``LIBCXX_ENABLE_UNICODE``
 
+ * A C++20 based extension
+
 Some of the current limitations
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
  * There is no official build system support, libc++ has experimental CMake support
+ * Requires CMake 3.26 for C++20 support
  * Requires CMake 3.26 for C++23 support
  * Requires CMake 3.27 for C++26 support
  * Requires Ninja 1.11

diff  --git a/libcxx/docs/UsingLibcxx.rst b/libcxx/docs/UsingLibcxx.rst
index 1859645320a4056..71a934f4bf28726 100644
--- a/libcxx/docs/UsingLibcxx.rst
+++ b/libcxx/docs/UsingLibcxx.rst
@@ -520,6 +520,12 @@ in their code base.
 In C++26 formatting pointers gained a type ``P`` and allows to use
 zero-padding. These options have been retroactively applied to C++20.
 
+Extensions to the C++23 modules ``std`` and ``std.compat``
+----------------------------------------------------------
+
+Like other major implementations, libc++ provides C++23 modules ``std`` and
+``std.compat`` in C++20 as an extension"
+
 .. _turning-off-asan:
 
 Turning off ASan annotation in containers

diff  --git a/libcxx/modules/std/algorithm.inc b/libcxx/modules/std/algorithm.inc
index bb38f39df888961..c951b2b36c82739 100644
--- a/libcxx/modules/std/algorithm.inc
+++ b/libcxx/modules/std/algorithm.inc
@@ -150,10 +150,11 @@ export namespace std {
   }
 
   namespace ranges {
+#if _LIBCPP_STD_VER >= 23
     // [alg.starts.with], starts with
     using std::ranges::starts_with;
 
-#if 0
+#  if 0
     // [alg.ends.with], ends with
     using std::ranges::ends_with;
 
@@ -167,8 +168,9 @@ export namespace std {
     using std::ranges::fold_left_with_iter;
     using std::ranges::fold_left_first_with_iter;
     using std::ranges::fold_left_first_with_iter;
-#endif
-  } // namespace ranges
+#  endif
+#endif // _LIBCPP_STD_VER >= 23
+  }    // namespace ranges
 
   // [alg.modifying.operations], mutating sequence operations
   // [alg.copy], copy

diff  --git a/libcxx/modules/std/bit.inc b/libcxx/modules/std/bit.inc
index 2a05a8ee46dc4b7..027a6c17ad6a6b0 100644
--- a/libcxx/modules/std/bit.inc
+++ b/libcxx/modules/std/bit.inc
@@ -11,8 +11,10 @@ export namespace std {
   // [bit.cast], bit_cast
   using std::bit_cast;
 
+#if _LIBCPP_STD_VER >= 23
   // [bit.byteswap], byteswap
   using std::byteswap;
+#endif
 
   // [bit.pow.two], integral powers of 2
   using std::bit_ceil;

diff  --git a/libcxx/modules/std/expected.inc b/libcxx/modules/std/expected.inc
index 1595230123dea89..c21683cb90d6348 100644
--- a/libcxx/modules/std/expected.inc
+++ b/libcxx/modules/std/expected.inc
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 export namespace std {
+#if _LIBCPP_STD_VER >= 23
   // [expected.unexpected], class template unexpected
   using std::unexpected;
 
@@ -20,4 +21,5 @@ export namespace std {
 
   // [expected.expected], class template expected
   using std::expected;
+#endif // _LIBCPP_STD_VER >= 23
 } // namespace std

diff  --git a/libcxx/modules/std/format.inc b/libcxx/modules/std/format.inc
index ae7de95495cf8c5..c1bc91f8317dd0a 100644
--- a/libcxx/modules/std/format.inc
+++ b/libcxx/modules/std/format.inc
@@ -42,8 +42,10 @@ export namespace std {
   // [format.formatter], formatter
   using std::formatter;
 
+#if _LIBCPP_STD_VER >= 23
   // [format.formattable], concept formattable
   using std::formattable;
+#endif
 
   // [format.parse.ctx], class template basic_format_parse_context
   using std::basic_format_parse_context;
@@ -52,6 +54,7 @@ export namespace std {
   using std::wformat_parse_context;
 #endif
 
+#if _LIBCPP_STD_VER >= 23
   // [format.range], formatting of ranges
   // [format.range.fmtkind], variable template format_kind
   using std::format_kind;
@@ -59,6 +62,7 @@ export namespace std {
 
   // [format.range.formatter], class template range_formatter
   using std::range_formatter;
+#endif // _LIBCPP_STD_VER >= 23
 
   // [format.arg], class template basic_format_arg
   using std::basic_format_arg;

diff  --git a/libcxx/modules/std/functional.inc b/libcxx/modules/std/functional.inc
index f8a29e2f058f8f2..1148944a9d2fee3 100644
--- a/libcxx/modules/std/functional.inc
+++ b/libcxx/modules/std/functional.inc
@@ -10,7 +10,9 @@
 export namespace std {
   // [func.invoke], invoke
   using std::invoke;
+#if _LIBCPP_STD_VER >= 23
   using std::invoke_r;
+#endif
 
   // [refwrap], reference_wrapper
   using std::reference_wrapper;

diff  --git a/libcxx/modules/std/mdspan.inc b/libcxx/modules/std/mdspan.inc
index 37580eaa458b41b..888c94ad59cfd9a 100644
--- a/libcxx/modules/std/mdspan.inc
+++ b/libcxx/modules/std/mdspan.inc
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 export namespace std {
+#if _LIBCPP_STD_VER >= 23
   // [mdspan.extents], class template extents
   using std::extents;
 
@@ -24,4 +25,5 @@ export namespace std {
 
   // [mdspan.mdspan], class template mdspan
   using std::mdspan;
+#endif // _LIBCPP_STD_VER >= 23
 } // namespace std

diff  --git a/libcxx/modules/std/memory.inc b/libcxx/modules/std/memory.inc
index d91c549e854f90c..fba2461732c1b9d 100644
--- a/libcxx/modules/std/memory.inc
+++ b/libcxx/modules/std/memory.inc
@@ -41,9 +41,11 @@ export namespace std {
   // [allocator.traits], allocator traits
   using std::allocator_traits;
 
+#if _LIBCPP_STD_VER >= 23
   using std::allocation_result;
 
   using std::allocate_at_least;
+#endif
 
   // [default.allocator], the default allocator
   using std::allocator;

diff  --git a/libcxx/modules/std/print.inc b/libcxx/modules/std/print.inc
index 35a1635cf201f39..1ca52c700688721 100644
--- a/libcxx/modules/std/print.inc
+++ b/libcxx/modules/std/print.inc
@@ -8,12 +8,14 @@
 //===----------------------------------------------------------------------===//
 
 export namespace std {
+#if _LIBCPP_STD_VER >= 23
   // [print.fun], print functions
   using std::print;
   using std::println;
 
   using std::vprint_nonunicode;
-#ifndef _LIBCPP_HAS_NO_UNICODE
+#  ifndef _LIBCPP_HAS_NO_UNICODE
   using std::vprint_unicode;
-#endif // _LIBCPP_HAS_NO_UNICODE
+#  endif // _LIBCPP_HAS_NO_UNICODE
+#endif   // _LIBCPP_STD_VER >= 23
 } // namespace std

diff  --git a/libcxx/modules/std/ranges.inc b/libcxx/modules/std/ranges.inc
index a6b1bf5496251a8..67b0f02ad9d980f 100644
--- a/libcxx/modules/std/ranges.inc
+++ b/libcxx/modules/std/ranges.inc
@@ -90,8 +90,10 @@ export namespace std {
 
     using std::ranges::borrowed_subrange_t;
 
+#if _LIBCPP_STD_VER >= 23
     // [range.utility.conv], range conversions
     using std::ranges::to;
+#endif
 
     // [range.empty], empty view
     using std::ranges::empty_view;
@@ -114,12 +116,14 @@ export namespace std {
       using std::ranges::views::iota;
     } // namespace views
 
+#if _LIBCPP_STD_VER >= 23
     // [range.repeat], repeat view
     using std::ranges::repeat_view;
 
     namespace views {
       using std::ranges::views::repeat;
     } // namespace views
+#endif // _LIBCPP_STD_VER >= 23
 
 #ifndef _LIBCPP_HAS_NO_LOCALIZATION
     // [range.istream], istream view
@@ -149,12 +153,14 @@ export namespace std {
     // [range.owning.view], owning view
     using std::ranges::owning_view;
 
+#if _LIBCPP_STD_VER >= 23
     // [range.as.rvalue], as rvalue view
     using std::ranges::as_rvalue_view;
 
     namespace views {
       using std::ranges::views::as_rvalue;
     } // namespace views
+#endif // _LIBCPP_STD_VER >= 23
 
     // [range.filter], filter view
     using std::ranges::filter_view;
@@ -259,12 +265,14 @@ export namespace std {
       using std::ranges::views::values;
     } // namespace views
 
+#if _LIBCPP_STD_VER >= 23
     // [range.zip], zip view
     using std::ranges::zip_view;
 
     namespace views {
       using std::ranges::views::zip;
     } // namespace views
+#endif // _LIBCPP_STD_VER >= 23
 
 #if 0
     // [range.zip.transform], zip transform view
@@ -329,6 +337,8 @@ export namespace std {
   using std::tuple_element;
   using std::tuple_size;
 
+#if _LIBCPP_STD_VER >= 23
   using std::from_range;
   using std::from_range_t;
+#endif // _LIBCPP_STD_VER >= 23
 } // namespace std

diff  --git a/libcxx/modules/std/string.inc b/libcxx/modules/std/string.inc
index 76b384c8b54be48..8366690fd9d37d0 100644
--- a/libcxx/modules/std/string.inc
+++ b/libcxx/modules/std/string.inc
@@ -68,7 +68,7 @@ export namespace std {
   using std::hash;
 
   // TODO MODULES is this a bug?
-#if 1
+#if _LIBCPP_STD_VER >= 23
   using std::operator""s;
 #else
   inline namespace literals {

diff  --git a/libcxx/modules/std/thread.inc b/libcxx/modules/std/thread.inc
index 114840e3d1cbf9f..43594d1a29cf305 100644
--- a/libcxx/modules/std/thread.inc
+++ b/libcxx/modules/std/thread.inc
@@ -33,7 +33,9 @@ export namespace std {
   using std::operator<<;
 #  endif // _LIBCPP_HAS_NO_LOCALIZATION
 
+#  if _LIBCPP_STD_VER >= 23
   using std::formatter;
+#  endif
 
   using std::hash;
 #endif // _LIBCPP_HAS_NO_THREADS

diff  --git a/libcxx/modules/std/tuple.inc b/libcxx/modules/std/tuple.inc
index 9a8fb72cb63ea53..706e2266c174b77 100644
--- a/libcxx/modules/std/tuple.inc
+++ b/libcxx/modules/std/tuple.inc
@@ -13,9 +13,11 @@ export namespace std {
 
   // [tuple.like], concept tuple-like
 
+#if _LIBCPP_STD_VER >= 23
   // [tuple.common.ref], common_reference related specializations
   using std::basic_common_reference;
   using std::common_type;
+#endif
 
   // [tuple.creation], tuple creation functions
   using std::ignore;

diff  --git a/libcxx/modules/std/type_traits.inc b/libcxx/modules/std/type_traits.inc
index f0ec4cb6c71a301..d368daf35ccb8c0 100644
--- a/libcxx/modules/std/type_traits.inc
+++ b/libcxx/modules/std/type_traits.inc
@@ -53,7 +53,9 @@ export namespace std {
   using std::is_volatile;
 
   using std::is_bounded_array;
+#if _LIBCPP_STD_VER >= 23
   using std::is_scoped_enum;
+#endif
   using std::is_signed;
   using std::is_unbounded_array;
   using std::is_unsigned;
@@ -255,7 +257,9 @@ export namespace std {
   using std::is_nothrow_swappable_v;
   using std::is_nothrow_swappable_with_v;
   using std::is_polymorphic_v;
+#if _LIBCPP_STD_VER >= 23
   using std::is_scoped_enum_v;
+#endif
   using std::is_signed_v;
   using std::is_standard_layout_v;
   using std::is_swappable_v;

diff  --git a/libcxx/modules/std/utility.inc b/libcxx/modules/std/utility.inc
index c8e4dc396cff3e9..77c21b87640dd46 100644
--- a/libcxx/modules/std/utility.inc
+++ b/libcxx/modules/std/utility.inc
@@ -16,7 +16,9 @@ export namespace std {
 
   // [forward], forward/move
   using std::forward;
+#if _LIBCPP_STD_VER >= 23
   using std::forward_like;
+#endif
   using std::move;
   using std::move_if_noexcept;
 
@@ -37,11 +39,13 @@ export namespace std {
 
   using std::in_range;
 
+#if _LIBCPP_STD_VER >= 23
   // [utility.underlying], to_underlying
   using std::to_underlying;
 
   // [utility.unreachable], unreachable
   using std::unreachable;
+#endif // _LIBCPP_STD_VER >= 23
 
   // [intseq], compile-time integer sequences
   using std::index_sequence;
@@ -55,8 +59,10 @@ export namespace std {
   // [pairs], class template pair
   using std::pair;
 
+#if _LIBCPP_STD_VER >= 23
   using std::basic_common_reference;
   using std::common_type;
+#endif
   // [pairs.spec], pair specialized algorithms
   using std::operator==;
   using std::operator<=>;

diff  --git a/libcxx/modules/std/vector.inc b/libcxx/modules/std/vector.inc
index a9ce764fc81da88..7168ec2bb703572 100644
--- a/libcxx/modules/std/vector.inc
+++ b/libcxx/modules/std/vector.inc
@@ -27,6 +27,8 @@ export namespace std {
   // hash support
   using std::hash;
 
+#if _LIBCPP_STD_VER >= 23
   // [vector.bool.fmt], formatter specialization for vector<bool>
   using std::formatter;
+#endif
 } // namespace std

diff  --git a/libcxx/test/libcxx/module_std.gen.py b/libcxx/test/libcxx/module_std.gen.py
index 2a6b0f237afc7d3..8bd4f702c7fc9b7 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -117,7 +117,7 @@
 print(
     f"""\
 //--- module_std.sh.cpp
-// UNSUPPORTED{BLOCKLIT}: c++03, c++11, c++14, c++17, c++20
+// UNSUPPORTED{BLOCKLIT}: c++03, c++11, c++14, c++17
 // UNSUPPORTED{BLOCKLIT}: libcpp-has-no-std-modules
 // UNSUPPORTED{BLOCKLIT}: modules-build
 

diff  --git a/libcxx/test/lit.local.cfg b/libcxx/test/lit.local.cfg
index 16ab3b1b622a1c0..ede8c65d89a0ba6 100644
--- a/libcxx/test/lit.local.cfg
+++ b/libcxx/test/lit.local.cfg
@@ -34,6 +34,8 @@ if std == "cxx26":
     std = "26"
 elif std == "cxx23":
     std = "23"
+elif std == "cxx20":
+    std = "20"
 else:
     std = ""
 

diff  --git a/libcxx/utils/ci/buildkite-pipeline.yml b/libcxx/utils/ci/buildkite-pipeline.yml
index 723ae438619745f..5c1010e81a9c5c9 100644
--- a/libcxx/utils/ci/buildkite-pipeline.yml
+++ b/libcxx/utils/ci/buildkite-pipeline.yml
@@ -218,9 +218,13 @@ steps:
       - "**/test-results.xml"
       - "**/*.abilist"
     env:
-        CC: "clang-${LLVM_HEAD_VERSION}"
-        CXX: "clang++-${LLVM_HEAD_VERSION}"
+        # Note: Modules require and absolute path for clang-scan-deps
+        # https://github.com/llvm/llvm-project/issues/61006
+        CC: "/usr/lib/llvm-${LLVM_HEAD_VERSION}/bin/clang"
+        CXX: "/usr/lib/llvm-${LLVM_HEAD_VERSION}/bin/clang++"
+        CMAKE: "/opt/bin/cmake"
         ENABLE_CLANG_TIDY: "On"
+        ENABLE_STD_MODULES: "On"
     agents:
       queue: "libcxx-builders"
       os: "linux"


        


More information about the libcxx-commits mailing list