r187266 - PR16708: If a lambda has an implicit return type, don't get confused if its return type has already been determined to be a type containing an 'auto'.
Richard Smith
richard-llvm at metafoo.co.uk
Fri Jul 26 15:53:54 PDT 2013
Author: rsmith
Date: Fri Jul 26 17:53:54 2013
New Revision: 187266
URL: http://llvm.org/viewvc/llvm-project?rev=187266&view=rev
Log:
PR16708: If a lambda has an implicit return type, don't get confused if its return type has already been determined to be a type containing an 'auto'.
Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaCXX/lambda-expressions.cpp
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=187266&r1=187265&r2=187266&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Jul 26 17:53:54 2013
@@ -2368,23 +2368,8 @@ Sema::ActOnCapScopeReturnStmt(SourceLoca
// For blocks/lambdas with implicit return types, we check each return
// statement individually, and deduce the common return type when the block
// or lambda is completed.
- if (AutoType *AT =
- FnRetType.isNull() ? 0 : FnRetType->getContainedAutoType()) {
- // In C++1y, the return type may involve 'auto'.
- FunctionDecl *FD = cast<LambdaScopeInfo>(CurCap)->CallOperator;
- if (CurContext->isDependentContext()) {
- // C++1y [dcl.spec.auto]p12:
- // Return type deduction [...] occurs when the definition is
- // instantiated even if the function body contains a return
- // statement with a non-type-dependent operand.
- CurCap->ReturnType = FnRetType = Context.DependentTy;
- } else if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
- FD->setInvalidDecl();
- return StmtError();
- } else
- CurCap->ReturnType = FnRetType = FD->getResultType();
- } else if (CurCap->HasImplicitReturnType) {
- // FIXME: Fold this into the 'auto' codepath above.
+ if (CurCap->HasImplicitReturnType) {
+ // FIXME: Fold this into the 'auto' codepath below.
if (RetValExp && !isa<InitListExpr>(RetValExp)) {
ExprResult Result = DefaultFunctionArrayLvalueConversion(RetValExp);
if (Result.isInvalid())
@@ -2411,6 +2396,21 @@ Sema::ActOnCapScopeReturnStmt(SourceLoca
// make sure we provide a return type now for better error recovery.
if (CurCap->ReturnType.isNull())
CurCap->ReturnType = FnRetType;
+ } else if (AutoType *AT =
+ FnRetType.isNull() ? 0 : FnRetType->getContainedAutoType()) {
+ // In C++1y, the return type may involve 'auto'.
+ FunctionDecl *FD = cast<LambdaScopeInfo>(CurCap)->CallOperator;
+ if (CurContext->isDependentContext()) {
+ // C++1y [dcl.spec.auto]p12:
+ // Return type deduction [...] occurs when the definition is
+ // instantiated even if the function body contains a return
+ // statement with a non-type-dependent operand.
+ CurCap->ReturnType = FnRetType = Context.DependentTy;
+ } else if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
+ FD->setInvalidDecl();
+ return StmtError();
+ } else
+ CurCap->ReturnType = FnRetType = FD->getResultType();
}
assert(!FnRetType.isNull());
Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=187266&r1=187265&r2=187266&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Fri Jul 26 17:53:54 2013
@@ -243,3 +243,11 @@ namespace PR13854 {
namespace PR14518 {
auto f = [](void) { return __func__; }; // no-warning
}
+
+namespace PR16708 {
+ auto L = []() {
+ auto ret = 0;
+ return ret;
+ return 0;
+ };
+}
More information about the cfe-commits
mailing list