Index: lib/Sema/SemaStmt.cpp =================================================================== --- lib/Sema/SemaStmt.cpp +++ lib/Sema/SemaStmt.cpp @@ -3031,9 +3031,10 @@ // 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()) { + if (AT->isDeduced() && !AT->isDependentType() && !FD->isInvalidDecl()) { AutoType *NewAT = Deduced->getContainedAutoType(); if (!FD->isDependentContext() && + !NewAT->isDependentType() && !Context.hasSameType(AT->getDeducedType(), NewAT->getDeducedType())) { const LambdaScopeInfo *LambdaSI = getCurLambda(); if (LambdaSI && LambdaSI->HasImplicitReturnType) { Index: test/SemaCXX/cxx14-auto-lambda-bad-return-1.cpp =================================================================== --- /dev/null +++ test/SemaCXX/cxx14-auto-lambda-bad-return-1.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s + +// First return triggers and error, the type of the second return is known +// (void). Type inference will try to reconcile these types and can get +// confused while doing so (bug 23189). + +void test() { + auto a = [] { + return b; // expected-error {{use of undeclared identifier 'b'}} + return; + }; +} Index: test/SemaCXX/cxx14-auto-lambda-bad-return-2.cpp =================================================================== --- /dev/null +++ test/SemaCXX/cxx14-auto-lambda-bad-return-2.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s + +// First return is properly typed (void) but the second one triggers an error. +// Type inference might still try to deduce the type of this lambda and can +// get confused while doing so (bug 23189). + +void test() { + auto a = [] { + return; + return &b; // expected-error {{use of undeclared identifier 'b'}} + }; +}