[SemaCXX] Fix crash-on-invalid while trying to deduce return type of a lambda.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 30 Jan 2016 01:51:20 +0000 (01:51 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 30 Jan 2016 01:51:20 +0000 (01:51 +0000)
rdar://22032373

llvm-svn: 259287

clang/lib/Sema/SemaStmt.cpp
clang/test/SemaCXX/lambda-expressions.cpp

index e1b1a47..d734416 100644 (file)
@@ -3066,22 +3066,23 @@ bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
   //  has multiple return statements, the return type is deduced for each return
   //  statement. [...] if the type deduced is not the same in each deduction,
   //  the program is ill-formed.
-  if (AT->isDeduced() && !FD->isInvalidDecl()) {
+  QualType DeducedT = AT->getDeducedType();
+  if (!DeducedT.isNull() && !FD->isInvalidDecl()) {
     AutoType *NewAT = Deduced->getContainedAutoType();
     CanQualType OldDeducedType = Context.getCanonicalFunctionResultType(
-                                   AT->getDeducedType());
+                                   DeducedT);
     CanQualType NewDeducedType = Context.getCanonicalFunctionResultType(
                                    NewAT->getDeducedType());
     if (!FD->isDependentContext() && OldDeducedType != NewDeducedType) {
       const LambdaScopeInfo *LambdaSI = getCurLambda();
       if (LambdaSI && LambdaSI->HasImplicitReturnType) {
         Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible)
-          << NewAT->getDeducedType() << AT->getDeducedType()
+          << NewAT->getDeducedType() << DeducedT
           << true /*IsLambda*/;
       } else {
         Diag(ReturnLoc, diag::err_auto_fn_different_deductions)
           << (AT->isDecltypeAuto() ? 1 : 0)
-          << NewAT->getDeducedType() << AT->getDeducedType();
+          << NewAT->getDeducedType() << DeducedT;
       }
       return true;
     }
index 72adcdb..08446a0 100644 (file)
@@ -476,3 +476,14 @@ int main() {
 
 A<int> a;
 }
+
+// rdar://22032373
+namespace rdar22032373 {
+void foo() {
+  auto blk = [](bool b) {
+    if (b)
+      return undeclared_error; // expected-error {{use of undeclared identifier}}
+    return 0;
+  };
+}
+}