diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 33354df69575c4..62e108ef07efb4 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -16744,8 +16744,17 @@ ExprResult Sema::ActOnStmtExprResult(ExprResult ER) { // to perform implicit conversion during the copy initialization. if (getCurScope()->isPatternScope()) { InspectExpr *IE = getCurFunction()->InspectStack.back().getPointer(); - if (IE->hasExplicitResultType()) - T = IE->getType(); + if (IE->hasExplicitResultType()) { + QualType ER = IE->getType(); + + // Catch this edge case where we can't make a valid + // statement expression result from a void type. + // All other cases should be caught elsewhere when + // we explore convertibility between the pattern + // substatement and the inspect return type. + if (!ER.getTypePtr()->isVoidType()) + T = ER; + } } // FIXME: Provide a better location for the initialization. diff --git a/clang/test/SemaCXX/inspect.cpp b/clang/test/SemaCXX/inspect.cpp index 8ed814d1556f84..c200405a7d6ae3 100644 --- a/clang/test/SemaCXX/inspect.cpp +++ b/clang/test/SemaCXX/inspect.cpp @@ -17,7 +17,7 @@ void a2() { void b(int x) { inspect(x) -> void { - __ => 3; // expected-error {{cannot initialize statement expression result of type 'void' with an rvalue of type 'int'}} + __ => 3; // expected-error {{resulting expression type 'int' must match trailing result type 'void'}} }; }