Skip to content

Commit 3456e9b

Browse files
dansarginsonbcardosolopes
authored andcommitted
[Pattern Matching] Fix bug causing incorrect diagnostic
Incorrect diagnostic can be emitted when using statement expressions as a pattern substatement in an inspect with a trailing `void` return type. Add a specific check for the void return type. All other cases are handled when we check for convertibility later in semantic analysis. fixes llvm#19
1 parent 7a851d3 commit 3456e9b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13979,8 +13979,17 @@ ExprResult Sema::ActOnStmtExprResult(ExprResult ER) {
1397913979
// to perform implicit conversion during the copy initialization.
1398013980
if (getCurScope()->isPatternScope()) {
1398113981
InspectExpr *IE = getCurFunction()->InspectStack.back().getPointer();
13982-
if (IE->hasExplicitResultType())
13983-
T = IE->getType();
13982+
if (IE->hasExplicitResultType()) {
13983+
QualType ER = IE->getType();
13984+
13985+
// Catch this edge case where we can't make a valid
13986+
// statement expression result from a void type.
13987+
// All other cases should be caught elsewhere when
13988+
// we explore convertibility between the pattern
13989+
// substatement and the inspect return type.
13990+
if (!ER.getTypePtr()->isVoidType())
13991+
T = ER;
13992+
}
1398413993
}
1398513994

1398613995
// FIXME: Provide a better location for the initialization.

clang/test/SemaCXX/inspect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void a2() {
1717

1818
void b(int x) {
1919
inspect(x) -> void {
20-
__ => 3; // expected-error {{cannot initialize statement expression result of type 'void' with an rvalue of type 'int'}}
20+
__ => 3; // expected-error {{resulting expression type 'int' must match trailing result type 'void'}}
2121
};
2222
}
2323

0 commit comments

Comments
 (0)