[clang] Add warning for blocks capturing {'this', raw pointers, references} (PR #144388)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 27 14:13:38 PDT 2025


================
@@ -1641,6 +1641,17 @@ def warn_implicitly_retains_self : Warning <
   "block implicitly retains 'self'; explicitly mention 'self' to indicate "
   "this is intended behavior">,
   InGroup<DiagGroup<"implicit-retain-self">>, DefaultIgnore;
+def warn_blocks_capturing_this : Warning<"block implicitly captures 'this'">,
+                                 InGroup<DiagGroup<"blocks-capturing-this">>,
+                                 DefaultIgnore;
+def warn_blocks_capturing_reference
+    : Warning<"block implicitly captures a C++ reference">,
+      InGroup<DiagGroup<"blocks-capturing-reference">>,
+      DefaultIgnore;
+def warn_blocks_capturing_raw_pointer
+    : Warning<"block implicitly captures a raw pointer">,
----------------
rjmccall wrote:

I don't like `__block` as a suppression mechanism, both because it adds real overhead and because it doesn't meaningfully change the danger. In fact, I don't think `__block` should be suppressing this warning at all.

I think you just need a new attribute to suppress the warning.

https://github.com/llvm/llvm-project/pull/144388


More information about the cfe-commits mailing list