https://github.com/BohdanYehorov updated 
https://github.com/llvm/llvm-project/pull/207583

>From b519880b0a6132b2b9fe556fe17423b2ac4fa161 Mon Sep 17 00:00:00 2001
From: Bohdan <[email protected]>
Date: Sun, 5 Jul 2026 14:40:05 +0300
Subject: [PATCH 1/2] [Sema] Add lambda decltype((x)) semantics to blocks
 (#207355)

---
 clang/lib/Sema/SemaType.cpp                    |  6 +++++-
 .../test/SemaObjCXX/decltype-block-capture.mm  | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaObjCXX/decltype-block-capture.mm

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 3640bf00b77a4..d2276479bc793 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -10065,7 +10065,11 @@ QualType Sema::getDecltypeForExpr(Expr *E) {
   //   access to a corresponding data member of the closure type that
   //   would have been declared if x were an odr-use of the denoted
   //   entity.
-  if (getCurLambda() && isa<ParenExpr>(IDExpr)) {
+
+  // decltype result for blocks should be the same as decltype result in 
+  // lambdas because blocks capture variables the same as lambdas do
+  // https://github.com/llvm/llvm-project/issues/207355#issuecomment-4877181419
+  if (isa<ParenExpr>(IDExpr)) {
     if (auto *DRE = dyn_cast<DeclRefExpr>(IDExpr->IgnoreParens())) {
       if (auto *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
         QualType T = getCapturedDeclRefType(Var, DRE->getLocation());
diff --git a/clang/test/SemaObjCXX/decltype-block-capture.mm 
b/clang/test/SemaObjCXX/decltype-block-capture.mm
new file mode 100644
index 0000000000000..ee64f2669e27e
--- /dev/null
+++ b/clang/test/SemaObjCXX/decltype-block-capture.mm
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -fblocks %s
+// expected-no-diagnostics
+template<typename T, typename U>
+inline constexpr bool is_same_as = false;
+
+template<typename T>
+inline constexpr bool is_same_as<T, T> = true;
+
+struct X {};
+
+void f() {
+    X x;
+
+    void (^b)(void) = ^{
+        decltype(auto) y = (x);
+        static_assert(is_same_as<decltype(y), decltype((x))>);
+    };
+}
\ No newline at end of file

>From 8008e6749d6ed2981a8355ceec63920e3c78a0de Mon Sep 17 00:00:00 2001
From: Bohdan <[email protected]>
Date: Sun, 5 Jul 2026 14:40:05 +0300
Subject: [PATCH 2/2] [Sema] Add lambda decltype((x)) semantics to blocks
 (#207355)

---
 clang/lib/Sema/SemaType.cpp                    |  2 +-
 .../test/SemaObjCXX/decltype-OpenMP-capture.mm | 17 +++++++++++++++++
 ...decltype-block-capture-__block-qualified.mm | 15 +++++++++++++++
 ...type-block-capture-non-__block-qualified.mm | 16 ++++++++++++++++
 .../decltype-block-in-lambda-capture.mm        | 18 ++++++++++++++++++
 .../decltype-lambda-in-block-capture.mm        | 18 ++++++++++++++++++
 6 files changed, 85 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaObjCXX/decltype-OpenMP-capture.mm
 create mode 100644 
clang/test/SemaObjCXX/decltype-block-capture-__block-qualified.mm
 create mode 100644 
clang/test/SemaObjCXX/decltype-block-capture-non-__block-qualified.mm
 create mode 100644 clang/test/SemaObjCXX/decltype-block-in-lambda-capture.mm
 create mode 100644 clang/test/SemaObjCXX/decltype-lambda-in-block-capture.mm

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 29af650848657..e90ef33b18a05 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -10056,7 +10056,7 @@ QualType Sema::getDecltypeForExpr(Expr *E) {
   //   would have been declared if x were an odr-use of the denoted
   //   entity.
 
-  // decltype result for blocks should be the same as decltype result in 
+  // decltype result for blocks should be the same as decltype result in
   // lambdas because blocks capture variables the same as lambdas do
   // https://github.com/llvm/llvm-project/issues/207355#issuecomment-4877181419
   if (isa<ParenExpr>(IDExpr)) {
diff --git a/clang/test/SemaObjCXX/decltype-OpenMP-capture.mm 
b/clang/test/SemaObjCXX/decltype-OpenMP-capture.mm
new file mode 100644
index 0000000000000..a7c03f0279372
--- /dev/null
+++ b/clang/test/SemaObjCXX/decltype-OpenMP-capture.mm
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -fblocks -fopenmp %s
+// expected-no-diagnostics
+
+template<typename T, typename U>
+inline constexpr bool is_same_as = false;
+
+template<typename T>
+inline constexpr bool is_same_as<T, T> = true;
+
+struct X {};
+void f() {
+    X x;
+    #pragma omp parallel
+    {
+        static_assert(is_same_as<decltype((x)), X&>);
+    }
+}
\ No newline at end of file
diff --git a/clang/test/SemaObjCXX/decltype-block-capture-__block-qualified.mm 
b/clang/test/SemaObjCXX/decltype-block-capture-__block-qualified.mm
new file mode 100644
index 0000000000000..df89ea479f1ec
--- /dev/null
+++ b/clang/test/SemaObjCXX/decltype-block-capture-__block-qualified.mm
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -fblocks %s
+// expected-no-diagnostics
+template<typename T, typename U>
+inline constexpr bool is_same_as = false;
+
+template<typename T>
+inline constexpr bool is_same_as<T, T> = true;
+
+struct X {};
+void f() {
+    __block X x;
+    void (^b)(void) = ^{
+        static_assert(is_same_as<decltype((x)), X&>);
+    };
+}
\ No newline at end of file
diff --git 
a/clang/test/SemaObjCXX/decltype-block-capture-non-__block-qualified.mm 
b/clang/test/SemaObjCXX/decltype-block-capture-non-__block-qualified.mm
new file mode 100644
index 0000000000000..a21a2f6643605
--- /dev/null
+++ b/clang/test/SemaObjCXX/decltype-block-capture-non-__block-qualified.mm
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -fblocks %s
+// expected-no-diagnostics
+
+template<typename T, typename U>
+inline constexpr bool is_same_as = false;
+
+template<typename T>
+inline constexpr bool is_same_as<T, T> = true;
+
+struct X {};
+void f() {
+    X x;
+    void (^b)(void) = ^{
+        static_assert(is_same_as<decltype((x)), const X&>);
+    };
+}
\ No newline at end of file
diff --git a/clang/test/SemaObjCXX/decltype-block-in-lambda-capture.mm 
b/clang/test/SemaObjCXX/decltype-block-in-lambda-capture.mm
new file mode 100644
index 0000000000000..b9af246af694a
--- /dev/null
+++ b/clang/test/SemaObjCXX/decltype-block-in-lambda-capture.mm
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -fblocks %s
+// expected-no-diagnostics
+
+template<typename T, typename U>
+inline constexpr bool is_same_as = false;
+
+template<typename T>
+inline constexpr bool is_same_as<T, T> = true;
+
+struct X {};
+void f() {
+    X x;
+    auto b = [&]() {
+        void (^c)(void) = ^{
+            static_assert(is_same_as<decltype((x)), X&>);
+        };
+    };
+}
\ No newline at end of file
diff --git a/clang/test/SemaObjCXX/decltype-lambda-in-block-capture.mm 
b/clang/test/SemaObjCXX/decltype-lambda-in-block-capture.mm
new file mode 100644
index 0000000000000..3b21205d1b5cd
--- /dev/null
+++ b/clang/test/SemaObjCXX/decltype-lambda-in-block-capture.mm
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -fblocks %s
+// expected-no-diagnostics
+
+template<typename T, typename U>
+inline constexpr bool is_same_as = false;
+
+template<typename T>
+inline constexpr bool is_same_as<T, T> = true;
+
+struct X {};
+void f() {
+    X x;
+    void (^b)(void) = ^{
+        auto c = [&]() {
+            static_assert(is_same_as<decltype((x)), const X&>);
+        };
+    };
+}
\ No newline at end of file

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

Reply via email to