diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3560,6 +3560,10 @@ CapturingScopeInfo *CurCap = cast(getCurFunction()); QualType FnRetType = CurCap->ReturnType; LambdaScopeInfo *CurLambda = dyn_cast(CurCap); + + if (CurLambda && !CurLambda->Lambda) + return StmtError(); + bool HasDeducedReturnType = CurLambda && hasDeducedReturnType(CurLambda->CallOperator); diff --git a/clang/test/Sema/returnstmt-in-lambda-declarator.cpp b/clang/test/Sema/returnstmt-in-lambda-declarator.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Sema/returnstmt-in-lambda-declarator.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11 + +void g() { + auto f = [](char c = ({ return 42; })) {}; // expected-error {{cannot initialize a parameter of type 'char' with an rvalue of type 'void'}} expected-note {{passing argument to parameter 'c' here}} +}