llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Oliver Hunt (ojhunt)

<details>
<summary>Changes</summary>

When parsing a block expression we were not entering a new eval context and as 
a result when parsing the block body we continue to treat any return statements 
as discarded so infer a `void` result.

This fixes the problem by introducing an evaluation context around the parsing 
of the body.

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


2 Files Affected:

- (modified) clang/lib/Parse/ParseExpr.cpp (+2-1) 
- (modified) clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp (+10) 


``````````diff
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index bc238a9517a37..d9e86405d338d 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3342,7 +3342,8 @@ ExprResult Parser::ParseBlockLiteralExpression() {
     Actions.ActOnBlockError(CaretLoc, getCurScope());
     return ExprError();
   }
-
+ EnterExpressionEvaluationContextForFunction PotentiallyEvaluated(
+       Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
   StmtResult Stmt(ParseCompoundStatementBody());
   BlockScope.Exit();
   if (!Stmt.isInvalid())
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
index 05830de9891fe..4c3c23164908e 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1z -verify %s
+// RUN: %clang_cc1 -std=c++1z -fblocks -verify %s -DBLOCK_TEST
 // RUN: %clang_cc1 -std=c++1z -verify %s -DUNDEFINED
 
 #ifdef UNDEFINED
@@ -254,6 +255,15 @@ namespace GH153884 {
     // expected-note@-1 {{in instantiation of function template specialization 
'GH153884::f2()}}
     return false;
   }
+
+#if BLOCK_TEST
+void  block_receiver(int (^)() );
+int f3() {
+  if constexpr (0)
+    (block_receiver)(^{ return 2; });
+  return 1;
+}
+#endif
 }
 
 #endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/154109
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to