[libc++] Mark <filesystem> as unavailable on Apple platforms using pragmas
Summary:
Also add the corresponding XFAILs to tests that require filesystem.
The approach taken to mark <filesystem> as unavailable in this patch
is to mark all the header as unavailable using #pragma clang attribute.
Marking each declaration using the attribute is more intrusive and
does not provide a lot of value right now because pretty much everything
in <filesystem> requires dylib support, often transitively.
This is an alternative to https://reviews.llvm.org/D59093.
A similar (but partial) patch was already applied in r356558.
Reviewers: mclow.lists, EricWF, serge-sans-paille
Subscribers: christof, jkorous, dexonsmith, libcxx-commits
Differential Revision: https://reviews.llvm.org/D59224
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@356616 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__config b/include/__config
index c9c634d..b942370 100644
--- a/include/__config
+++ b/include/__config
@@ -1311,7 +1311,8 @@
#if !defined(_LIBCPP_BUILDING_LIBRARY) && \
!defined(_LIBCPP_DISABLE_AVAILABILITY) && \
__has_feature(attribute_availability_with_strict) && \
- __has_feature(attribute_availability_in_templates)
+ __has_feature(attribute_availability_in_templates) && \
+ __has_extension(pragma_clang_attribute_external_declaration)
# ifdef __APPLE__
# define _LIBCPP_USE_AVAILABILITY_APPLE
# endif
@@ -1359,6 +1360,16 @@
__attribute__((availability(ios,strict,unavailable))) \
__attribute__((availability(tvos,strict,unavailable))) \
__attribute__((availability(watchos,strict,unavailable)))
+# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH \
+ _Pragma("clang attribute push(__attribute__((availability(macosx,strict,unavailable))), apply_to=any(function,record))") \
+ _Pragma("clang attribute push(__attribute__((availability(ios,strict,unavailable))), apply_to=any(function,record))") \
+ _Pragma("clang attribute push(__attribute__((availability(tvos,strict,unavailable))), apply_to=any(function,record))") \
+ _Pragma("clang attribute push(__attribute__((availability(watchos,strict,unavailable))), apply_to=any(function,record))")
+# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP \
+ _Pragma("clang attribute pop") \
+ _Pragma("clang attribute pop") \
+ _Pragma("clang attribute pop") \
+ _Pragma("clang attribute pop")
#else
# define _LIBCPP_AVAILABILITY_SHARED_MUTEX
# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
@@ -1371,6 +1382,8 @@
# define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
# define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
# define _LIBCPP_AVAILABILITY_FILESYSTEM
+# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP
#endif
// Define availability that depends on _LIBCPP_NO_EXCEPTIONS.
diff --git a/include/chrono b/include/chrono
index a003751..b70aded 100644
--- a/include/chrono
+++ b/include/chrono
@@ -2841,7 +2841,7 @@
static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
- _LIBCPP_FUNC_VIS static time_point now() noexcept;
+ _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept;
_LIBCPP_INLINE_VISIBILITY
static time_t to_time_t(const time_point& __t) noexcept {
diff --git a/include/filesystem b/include/filesystem
index d599b54..3aaa798 100644
--- a/include/filesystem
+++ b/include/filesystem
@@ -258,6 +258,8 @@
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
typedef chrono::time_point<_FilesystemClock> file_time_type;
struct _LIBCPP_TYPE_VIS space_info {
@@ -1310,7 +1312,11 @@
return !(__lhs == __rhs);
}
-class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
+// TODO(ldionne): We need to pop the pragma and push it again after
+// filesystem_error to work around PR41078.
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
+class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error {
public:
_LIBCPP_INLINE_VISIBILITY
filesystem_error(const string& __what, error_code __ec)
@@ -1361,6 +1367,8 @@
shared_ptr<_Storage> __storage_;
};
+_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
+
template <class... _Args>
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
#ifndef _LIBCPP_NO_EXCEPTIONS
@@ -2624,6 +2632,8 @@
return recursive_directory_iterator();
}
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // !_LIBCPP_CXX03_LANG
diff --git a/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp b/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp
index 34244a8..2bc53a2 100644
--- a/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp
+++ b/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp
@@ -12,6 +12,8 @@
// violation because Clock::is_steady is defined in both the dylib and this TU.
// UNSUPPORTED: asan
+// XFAIL: dylib-has-no-filesystem
+
// <chrono>
// file_clock
diff --git a/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp b/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp
index 61d9238..07c5aa6 100644
--- a/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp
+++ b/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// XFAIL: dylib-has-no-filesystem
// <chrono>
diff --git a/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp b/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp
index c87fad2..69d91f5 100644
--- a/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp
+++ b/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// XFAIL: dylib-has-no-filesystem
// <chrono>