https://github.com/tshakalekholoane created 
https://github.com/llvm/llvm-project/pull/223355

None

>From 839ac6d033ec24a46e7b12dd045f3bdbd0f1e625 Mon Sep 17 00:00:00 2001
From: Tshaka Lekholoane <[email protected]>
Date: Sun, 2 Aug 2026 19:32:25 +0200
Subject: [PATCH] [clang-format] Add space after return type for block literal

---
 clang/lib/Format/TokenAnnotator.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 32ae8990f52c5..996705f1bdc6f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5044,6 +5044,17 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
     return true;
   // Space before parentheses common for all languages
   if (Right.is(tok::l_paren)) {
+    // Space between the return type and the parameter list of an
+    // Objective-C/Blocks block literal that has an explicit return
+    // type, e.g. ^bool (int x) { ... }. Note that a block literal with
+    // no explicit return type, e.g. ^(int x) { ... }, is deliberately
+    // left alone: Left is the caret itself in that case, not an
+    // identifier.
+    if (BeforeLeft && BeforeLeft->is(tok::caret) &&
+        BeforeLeft->is(TT_UnaryOperator) &&
+        (Left.is(tok::identifier) || Left.isTypeName(LangOpts))) {
+      return true;
+    }
     // Function declaration or definition
     if (Line.MightBeFunctionDecl && Right.is(TT_FunctionDeclarationLParen)) {
       if (spaceRequiredBeforeParens(Right))

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to