8000 [Pattern Matching] Fix bug causing incorrect diagnostic · ronchaine/llvm-project@611bd6e · GitHub
[go: up one dir, main page]

Skip to content

Commit 611bd6e

Browse files
dansarginsonJari Ronkainen
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 d50d93e commit 611bd6e

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
@@ -16744,8 +16744,17 @@ ExprResult Sema::ActOnStmtExprResult(ExprResult ER) {
1674416744
// to perform implicit conversion during the copy initialization.
1674516745
if (getCurScope()->isPatternScope()) {
1674616746
InspectExpr *IE = getCurFunction()->InspectStack.back().getPointer();
16747-
if (IE->hasExplicitResultType())
16748-
T = IE->getType();
16747+
if (IE->hasExplicitResultType()) {
16748+
QualType ER = IE->getType();
16749+
16750+
// Catch this edge case where we can't make a valid
16751+
// statement expression result from a void type.
16752+
// All other cases should be caught elsewhere when
16753+
// we explore convertibility between the pattern
16754+
// substatement and the inspect return type.
16755+
if (!ER.getTypePtr()->isVoidType())
16756+
T = ER;
16757+
}
1674916758
}
1675016759

1675116760
// 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)
0