From 056848c2f9bc5527fa2d7067b0e92c4214d05029 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 30 Jan 2016 01:51:20 +0000 Subject: [PATCH] [SemaCXX] Fix crash-on-invalid while trying to deduce return type of a lambda. rdar://22032373 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259287 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaStmt.cpp | 9 +++++---- test/SemaCXX/lambda-expressions.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index e1b1a47e18..d73441646b 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -3066,22 +3066,23 @@ bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, // has multiple return statements, the return type is deduced for each return // statement. [...] if the type deduced is not the same in each deduction, // the program is ill-formed. - if (AT->isDeduced() && !FD->isInvalidDecl()) { + QualType DeducedT = AT->getDeducedType(); + if (!DeducedT.isNull() && !FD->isInvalidDecl()) { AutoType *NewAT = Deduced->getContainedAutoType(); CanQualType OldDeducedType = Context.getCanonicalFunctionResultType( - AT->getDeducedType()); + DeducedT); CanQualType NewDeducedType = Context.getCanonicalFunctionResultType( NewAT->getDeducedType()); if (!FD->isDependentContext() && OldDeducedType != NewDeducedType) { const LambdaScopeInfo *LambdaSI = getCurLambda(); if (LambdaSI && LambdaSI->HasImplicitReturnType) { Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible) - << NewAT->getDeducedType() << AT->getDeducedType() + << NewAT->getDeducedType() << DeducedT << true /*IsLambda*/; } else { Diag(ReturnLoc, diag::err_auto_fn_different_deductions) << (AT->isDecltypeAuto() ? 1 : 0) - << NewAT->getDeducedType() << AT->getDeducedType(); + << NewAT->getDeducedType() << DeducedT; } return true; } diff --git a/test/SemaCXX/lambda-expressions.cpp b/test/SemaCXX/lambda-expressions.cpp index 72adcdbce2..08446a0ee4 100644 --- a/test/SemaCXX/lambda-expressions.cpp +++ b/test/SemaCXX/lambda-expressions.cpp @@ -476,3 +476,14 @@ int main() { A a; } + +// rdar://22032373 +namespace rdar22032373 { +void foo() { + auto blk = [](bool b) { + if (b) + return undeclared_error; // expected-error {{use of undeclared identifier}} + return 0; + }; +} +} -- 2.40.0