Skip to content

Commit f76c424

Browse files
committed
[libc++] Improve the detection of whether the blocks runtime is available
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
1 parent 53dd72a commit f76c424

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

libcxx/include/__config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ typedef __char32_t char32_t;
474474
# define _LIBCPP_HAS_EXTENSION_BLOCKS
475475
#endif
476476

477+
#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
478+
# define _LIBCPP_HAS_BLOCKS_RUNTIME
479+
#endif
480+
477481
#if !(__has_feature(cxx_relaxed_constexpr))
478482
#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
479483
#endif

libcxx/include/functional

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ POLICY: For non-variadic implementations, the number of arguments is limited
508508

509509
#include <__functional_base>
510510

511-
#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && !defined(_LIBCPP_HAS_OBJC_ARC) && __has_include(<Block.h>)
511+
#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
512512
#include <Block.h>
513513
#endif
514514

@@ -2255,7 +2255,7 @@ template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
22552255
#endif // _LIBCPP_NO_RTTI
22562256
};
22572257

2258-
#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && !defined(_LIBCPP_HAS_OBJC_ARC) && __has_include(<Block.h>)
2258+
#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
22592259

22602260
template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
22612261
class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>

libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
// std::function support for the "blocks" extension
1010

1111
// UNSUPPORTED: c++98, c++03
12-
// REQUIRES: has-fblocks
12+
13+
// This test requires the Blocks runtime, which is (only?) available
14+
// on Darwin out-of-the-box.
15+
// REQUIRES: has-fblocks && darwin
1316

1417
// FILE_DEPENDENCIES: %t.exe
1518
// RUN: %{build} -fblocks
1619
// RUN: %{run}
1720

18-
#if __has_include(<Block.h>)
19-
2021
#include <functional>
2122
#include <cstdlib>
2223
#include <cassert>
@@ -143,9 +144,3 @@ int main(int, char**)
143144

144145
return 0;
145146
}
146-
147-
#else
148-
149-
int main() { }
150-
151-
#endif

0 commit comments

Comments
 (0)