Skip to content

Commit b5b6ddc

Browse files
committed
[clang][ObjC] Fix incorrect return type inference for discarded blocks
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.
1 parent 8f671a6 commit b5b6ddc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3342,7 +3342,8 @@ ExprResult Parser::ParseBlockLiteralExpression() {
33423342
Actions.ActOnBlockError(CaretLoc, getCurScope());
33433343
return ExprError();
33443344
}
3345-
3345+
EnterExpressionEvaluationContextForFunction PotentiallyEvaluated(
3346+
Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
33463347
StmtResult Stmt(ParseCompoundStatementBody());
33473348
BlockScope.Exit();
33483349
if (!Stmt.isInvalid())

clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -std=c++1z -verify %s
2+
// RUN: %clang_cc1 -std=c++1z -fblocks -verify %s -DBLOCK_TEST
23
// RUN: %clang_cc1 -std=c++1z -verify %s -DUNDEFINED
34

45
#ifdef UNDEFINED
@@ -254,6 +255,15 @@ namespace GH153884 {
254255
// expected-note@-1 {{in instantiation of function template specialization 'GH153884::f2()}}
255256
return false;
256257
}
258+
259+
#if BLOCK_TEST
260+
void block_receiver(int (^)() );
261+
int f3() {
262+
if constexpr (0)
263+
(block_receiver)(^{ return 2; });
264+
return 1;
265+
}
266+
#endif
257267
}
258268

259269
#endif

0 commit comments

Comments
 (0)