llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: BohdanYehorov

<details>
<summary>Changes</summary>



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


2 Files Affected:

- (modified) clang/lib/Sema/SemaType.cpp (+5-1) 
- (added) clang/test/SemaObjCXX/decltype-block-capture.mm (+18) 


``````````diff
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

``````````

</details>


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

Reply via email to