[clang] [Sema] Add lambda decltype((x)) semantics to blocks (#207355) (PR #207583)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 5 06:18:33 PDT 2026
https://github.com/BohdanYehorov updated https://github.com/llvm/llvm-project/pull/207583
>From b519880b0a6132b2b9fe556fe17423b2ac4fa161 Mon Sep 17 00:00:00 2001
From: Bohdan <yehorovbohdan.work at gmail.com>
Date: Sun, 5 Jul 2026 14:40:05 +0300
Subject: [PATCH] [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
More information about the cfe-commits
mailing list