[llvm-branch-commits] [libcxx] d4e3c50 - [libc++] Define `namespace views` in its own detail header.

Louis Dionne via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Apr 11 08:43:22 PDT 2022


Author: Arthur O'Dwyer
Date: 2022-04-11T11:39:16-04:00
New Revision: d4e3c50b2bda796636bb283ab1a615f3333f75d9

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

LOG: [libc++] Define `namespace views` in its own detail header.

Discovered in the comments on D118748: we would like this namespace
to exist anytime Ranges exists, regardless of whether concepts syntax
is supported. Also, we'd like to fully granularize the <ranges> header,
which means not putting any loose declarations at the top level.

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

(cherry picked from commit 44cdca37c01a58da94087be8ebd0ee2bd2ba724e)

Added: 
    libcxx/include/__ranges/views.h
    libcxx/test/libcxx/diagnostics/detail.headers/ranges/views.module.verify.cpp

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/module.modulemap
    libcxx/include/ranges

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 7fdf2ff27b344..53700fc9e2c46 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -350,6 +350,7 @@ set(files
   __ranges/take_view.h
   __ranges/transform_view.h
   __ranges/view_interface.h
+  __ranges/views.h
   __split_buffer
   __std_stream
   __string

diff  --git a/libcxx/include/__ranges/views.h b/libcxx/include/__ranges/views.h
new file mode 100644
index 0000000000000..8cc5ba3d2aca5
--- /dev/null
+++ b/libcxx/include/__ranges/views.h
@@ -0,0 +1,35 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___RANGES_VIEWS
+#define _LIBCPP___RANGES_VIEWS
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+namespace ranges {
+
+namespace views { }
+
+} // namespace ranges
+
+namespace views = ranges::views;
+
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___RANGES_VIEWS

diff  --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 749c17f8bc08f..9e3643faee095 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -817,6 +817,7 @@ module std [system] {
         export functional.__functional.perfect_forward
       }
       module view_interface         { private header "__ranges/view_interface.h" }
+      module views                  { private header "__ranges/views.h" }
     }
   }
   module ratio {

diff  --git a/libcxx/include/ranges b/libcxx/include/ranges
index 82ad7f4d507f2..9b831160d683a 100644
--- a/libcxx/include/ranges
+++ b/libcxx/include/ranges
@@ -223,6 +223,7 @@ namespace std::ranges {
 #include <__ranges/take_view.h>
 #include <__ranges/transform_view.h>
 #include <__ranges/view_interface.h>
+#include <__ranges/views.h>
 #include <compare>          // Required by the standard.
 #include <initializer_list> // Required by the standard.
 #include <iterator>         // Required by the standard.
@@ -233,14 +234,4 @@ namespace std::ranges {
 #pragma GCC system_header
 #endif
 
-#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-namespace views = ranges::views;
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
-
 #endif // _LIBCPP_RANGES

diff  --git a/libcxx/test/libcxx/diagnostics/detail.headers/ranges/views.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/ranges/views.module.verify.cpp
new file mode 100644
index 0000000000000..3b5b617096870
--- /dev/null
+++ b/libcxx/test/libcxx/diagnostics/detail.headers/ranges/views.module.verify.cpp
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: modules-build
+
+// WARNING: This test was generated by 'generate_private_header_tests.py'
+// and should not be edited manually.
+
+// expected-error@*:* {{use of private header from outside its module: '__ranges/views.h'}}
+#include <__ranges/views.h>


        


More information about the llvm-branch-commits mailing list