aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaStmt.cpp8
-rw-r--r--test/SemaObjC/method-no-context.m4
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 39b211f64b..e7dff6d5b3 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -785,9 +785,11 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) {
QualType FnRetType;
if (FunctionDecl *FD = getCurFunctionDecl())
FnRetType = FD->getResultType();
- else
- FnRetType = getCurMethodDecl()->getResultType();
-
+ else if (ObjCMethodDecl *MD = getCurMethodDecl())
+ FnRetType = MD->getResultType();
+ else // If we don't have a function/method context, bail.
+ return StmtError();
+
if (FnRetType->isVoidType()) {
if (RetValExp) {// C99 6.8.6.4p1 (ext_ since GCC warns)
unsigned D = diag::ext_return_has_expr;
diff --git a/test/SemaObjC/method-no-context.m b/test/SemaObjC/method-no-context.m
new file mode 100644
index 0000000000..484322e29e
--- /dev/null
+++ b/test/SemaObjC/method-no-context.m
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only -verify %s
+
+- im0 { int a; return 0; // expected-error{{missing context for method declaration}}
+// expected-error{{expected '}'}}