[libc++] Improve the detection of whether the blocks runtime is available
authorLouis Dionne <ldionne@apple.com>
Thu, 23 Apr 2020 20:47:52 +0000 (16:47 -0400)
committerLouis Dionne <ldionne@apple.com>
Fri, 24 Apr 2020 11:02:21 +0000 (07:02 -0400)
The runtime for Blocks may not be available even though the Blocks
language extension _is_ available. Instead of potentially failing,
this commit is much more conservative and assumes the runtime for
Blocks is only provided on Apple platforms.

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

libcxx/include/__config
libcxx/include/functional
libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp

index 42f59ea..bfde9e9 100644 (file)
@@ -474,6 +474,10 @@ typedef __char32_t char32_t;
 #  define _LIBCPP_HAS_EXTENSION_BLOCKS
 #endif
 
+#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
+#  define _LIBCPP_HAS_BLOCKS_RUNTIME
+#endif
+
 #if !(__has_feature(cxx_relaxed_constexpr))
 #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
 #endif
index 360ca6e..62b7d09 100644 (file)
@@ -508,7 +508,7 @@ POLICY:  For non-variadic implementations, the number of arguments is limited
 
 #include <__functional_base>
 
-#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && !defined(_LIBCPP_HAS_OBJC_ARC) && __has_include(<Block.h>)
+#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
 #include <Block.h>
 #endif
 
@@ -2255,7 +2255,7 @@ template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
 #endif // _LIBCPP_NO_RTTI
 };
 
-#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && !defined(_LIBCPP_HAS_OBJC_ARC) && __has_include(<Block.h>)
+#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
 
 template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
 class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
index 757b3f2..6f50f4c 100644 (file)
@@ -9,14 +9,15 @@
 // std::function support for the "blocks" extension
 
 // UNSUPPORTED: c++98, c++03
-// REQUIRES: has-fblocks
+
+// This test requires the Blocks runtime, which is (only?) available
+// on Darwin out-of-the-box.
+// REQUIRES: has-fblocks && darwin
 
 // FILE_DEPENDENCIES: %t.exe
 // RUN: %{build} -fblocks
 // RUN: %{run}
 
-#if __has_include(<Block.h>)
-
 #include <functional>
 #include <cstdlib>
 #include <cassert>
@@ -143,9 +144,3 @@ int main(int, char**)
 
     return 0;
 }
-
-#else
-
-int main() { }
-
-#endif