Don't allow deduction of a lambda result type from an initializer

list; it is not an expression.

llvm-svn: 150194
This commit is contained in:
Douglas Gregor 2012-02-09 18:40:39 +00:00
parent e6a90e3c3d
commit 940a550f0d
3 changed files with 13 additions and 2 deletions

View File

@ -4130,6 +4130,8 @@ def ext_lambda_implies_void_return : ExtWarn<
"C++11 requires lambda with omitted result type to consist of a single "
"return statement">,
InGroup<DiagGroup<"lambda-return">>;
def err_lambda_return_init_list : Error<
"cannot deduce lambda return type from initializer list">;
def err_operator_arrow_circular : Error<
"circular pointer delegation detected">;

View File

@ -1798,7 +1798,7 @@ Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
CapturingScopeInfo *CurCap = cast<CapturingScopeInfo>(getCurFunction());
if (CurCap->HasImplicitReturnType) {
QualType ReturnT;
if (RetValExp) {
if (RetValExp && !isa<InitListExpr>(RetValExp)) {
ExprResult Result = DefaultFunctionArrayLvalueConversion(RetValExp);
if (Result.isInvalid())
return StmtError();
@ -1808,7 +1808,15 @@ Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
ReturnT = RetValExp->getType();
else
ReturnT = Context.DependentTy;
} else {
} else {
if (RetValExp) {
// C++11 [expr.lambda.prim]p4 bans inferring the result from an
// initializer list, because it is not an expression (even
// though we represent it as one). We still deduce 'void'.
Diag(ReturnLoc, diag::err_lambda_return_init_list)
<< RetValExp->getSourceRange();
}
ReturnT = Context.VoidTy;
}
// We require the return types to strictly match here.

View File

@ -17,6 +17,7 @@ void infer_void_return_type(int i) {
switch (x) {
case 0: return get<void>();
case 1: return;
case 2: return { 1, 2.0 }; // expected-error{{cannot deduce lambda return type from initializer list}}
}
}(7);
}