Don't allow deduction of a lambda result type from an initializer
list; it is not an expression.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150194 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index aff79a6..b018357 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4130,6 +4130,8 @@
   "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">;
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index e49bcfa..0adfb94 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -1798,7 +1798,7 @@
   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 @@
         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.
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
index a3a29c0..cff0c09 100644
--- a/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
+++ b/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
@@ -17,6 +17,7 @@
     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);
 }