" or pick a deployment target that supports them">;
def err_block_returning_array_function : Error<
"block cannot return %select{array|function}0 type %1">;
+def warn_block_missing_return_type : Warning<
+ "block literal is missing explicit return type and "
+ "returns non-void values">,
+ InGroup<DiagGroup<"block-missing-explicit-return-type">>, DefaultIgnore;
// Builtin annotation string.
def err_builtin_annotation_not_string_constant : Error<
ExprCleanupObjects.push_back(Result->getBlockDecl());
ExprNeedsCleanups = true;
}
-
+
+ if (BSI->TheDecl->blockMissingReturnType() &&
+ !RetTy->isDependentType() &&
+ !Context.getCanonicalType(RetTy)->isVoidType())
+ Diag(CaretLoc, diag::warn_block_missing_return_type);
+
return Owned(Result);
}
--- /dev/null
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wblock-missing-explicit-return-type
+// rdar://10735698
+
+int f;
+int main() {
+ int (^bar)() = ^{ if (f) return 'a'; // expected-warning {{block literal is missing explicit return type and returns non-void values}}
+ else return 10;
+ };
+
+ void (^bar1)() = ^{ f = 100; };
+
+ void (^bar2)() = ^(void){ f = 100; };
+
+ int (^bar3)() = ^ int { if (f) return 'a';
+ else return 10;
+ };
+
+}
// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything %s 2>&1 | FileCheck -check-prefix=CHECK-everything %s
// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Werror %s 2>&1 | FileCheck -check-prefix=CHECK-everything-error %s
// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Wno-unused %s 2>&1 | FileCheck -check-prefix=CHECK-everything-no-unused %s
-// CHECK-everything: 6 warnings generated
-// CHECK-everything-error: 5 errors generated
-// CHECK-everything-no-unused: 5 warnings generated
+// CHECK-everything: 7 warnings generated
+// CHECK-everything-error: 6 errors generated
+// CHECK-everything-no-unused: 6 warnings generated