Skip to content

Conversation

@iidmsa
Copy link
Contributor

@iidmsa iidmsa commented Feb 4, 2026

Suppress ADL on Blocks runtime calls in std::function by wrapping function names in parentheses.

Suppress ADL on Blocks runtime calls in std::function by wrapping
function names in parentheses.
@iidmsa iidmsa requested a review from a team as a code owner February 4, 2026 06:07
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 4, 2026
@llvmbot
Copy link
Member

llvmbot commented Feb 4, 2026

@llvm/pr-subscribers-libcxx

Author: Fady Farag (iidmsa)

Changes

Suppress ADL on Blocks runtime calls in std::function by wrapping function names in parentheses.


Full diff: https://github.com/llvm/llvm-project/pull/179614.diff

1 Files Affected:

  • (modified) libcxx/include/__functional/function.h (+2-2)
diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h
index 121417f90ff01..7576350fdea9e 100644
--- a/libcxx/include/__functional/function.h
+++ b/libcxx/include/__functional/function.h
@@ -540,7 +540,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Rp(_ArgTypes...)> : public __base<_Rp(_Ar
 #    if __has_feature(objc_arc)
       : __f_(__f)
 #    else
-      : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
+      : __f_(reinterpret_cast<__block_type>(__f ? (_Block_copy)(__f) : nullptr))
 #    endif
   {
   }
@@ -563,7 +563,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Rp(_ArgTypes...)> : public __base<_Rp(_Ar
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT {
 #    if !__has_feature(objc_arc)
     if (__f_)
-      _Block_release(__f_);
+      (_Block_release)(__f_);
 #    endif
     __f_ = 0;
   }

: __f_(__f)
# else
: __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
: __f_(reinterpret_cast<__block_type>(__f ? (_Block_copy)(__f) : nullptr))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks a bit weird to me. Can we use ::_Block_copy instead? Ditto below.

Also, I think we should add test for this which uses "ADL-bomb" types, e.g.

struct incomplete;

template <class T>
struct holder { T t; };

using adl_unfriendly_block = holder<incomplete>* (^)();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that first, but it didn't build. _Block_copy and _Block_release are declared with extern "C" inside namespace std.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should be able to do std::_Block_copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants