"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">;
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();
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.