[libc++] Proper fix for libc++'s modulemap after D68480
authorLouis Dionne <ldionne@apple.com>
Mon, 24 Feb 2020 23:12:44 +0000 (18:12 -0500)
committerLouis Dionne <ldionne@apple.com>
Tue, 25 Feb 2020 16:31:10 +0000 (11:31 -0500)
Summary:
In libc++, we normally #ifdef out header content instead of #erroring
out when the Standard in use is insufficient for the requirements of
the header.

Reviewers: EricWF

Subscribers: jkorous, dexonsmith, libcxx-commits, teemperor

Tags: #libc

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

libcxx/include/barrier
libcxx/include/latch
libcxx/include/semaphore
libcxx/test/libcxx/modules/stds_include.sh.cpp [new file with mode: 0644]

index e6dc0a1..5ef8b78 100644 (file)
@@ -57,9 +57,7 @@ namespace std
 # error <barrier> is not supported on this single threaded system
 #endif
 
-#if _LIBCPP_STD_VER < 14
-# error <barrier> requires C++14 or later
-#endif
+#if _LIBCPP_STD_VER >= 14
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -319,4 +317,6 @@ public:
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // _LIBCPP_STD_VER >= 14
+
 #endif //_LIBCPP_BARRIER
index 7c8b2f5..c83f6bf 100644 (file)
@@ -49,9 +49,7 @@ namespace std
 # error <latch> is not supported on this single threaded system
 #endif
 
-#if _LIBCPP_STD_VER < 14
-# error <latch> requires C++14 or later
-#endif
+#if _LIBCPP_STD_VER >= 14
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -101,4 +99,6 @@ public:
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // _LIBCPP_STD_VER >= 14
+
 #endif //_LIBCPP_LATCH
index 77e3797..cd27534 100644 (file)
@@ -58,9 +58,7 @@ using binary_semaphore = counting_semaphore<1>;
 # error <semaphore> is not supported on this single threaded system
 #endif
 
-#if _LIBCPP_STD_VER < 14
-# error <semaphore> is requires C++14 or later
-#endif
+#if _LIBCPP_STD_VER >= 14
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -230,4 +228,6 @@ using binary_semaphore = counting_semaphore<1>;
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // _LIBCPP_STD_VER >= 14
+
 #endif //_LIBCPP_SEMAPHORE
diff --git a/libcxx/test/libcxx/modules/stds_include.sh.cpp b/libcxx/test/libcxx/modules/stds_include.sh.cpp
new file mode 100644 (file)
index 0000000..ce5bfb2
--- /dev/null
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Test that we can include libc++ headers when building with modules
+// enabled in various Standard modes. This is a common source of breakage
+// since the 'std' module will include all headers, so if something in a
+// header fails under a standard mode, importing anything will fail.
+
+// This test fails on Windows because the underlying libc headers on Windows
+// are not modular
+// XFAIL: LIBCXX-WINDOWS-FIXME
+
+// FIXME: The <atomic> header is not supported for single-threaded systems,
+// but still gets built as part of the 'std' module, which breaks the build.
+// XFAIL: libcpp-has-no-threads
+
+// REQUIRES: modules-support
+
+// NOTE: The -std=XXX flag is present in %flags, so we overwrite it by passing it after %flags.
+// RUN: %cxx %flags %compile_flags -fmodules -fcxx-modules -fsyntax-only -std=c++98 %s
+// RUN: %cxx %flags %compile_flags -fmodules -fcxx-modules -fsyntax-only -std=c++03 %s
+// RUN: %cxx %flags %compile_flags -fmodules -fcxx-modules -fsyntax-only -std=c++11 %s
+// RUN: %cxx %flags %compile_flags -fmodules -fcxx-modules -fsyntax-only -std=c++14 %s
+// RUN: %cxx %flags %compile_flags -fmodules -fcxx-modules -fsyntax-only -std=c++17 %s
+// RUN: %cxx %flags %compile_flags -fmodules -fcxx-modules -fsyntax-only -std=c++2a %s
+
+#include <vector>
+
+int main(int, char**) {
+  return 0;
+}