From da323adbb99cee19a203ead852d5d9bfebb23fb7 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Fri, 29 Feb 2008 21:48:07 +0000 Subject: [PATCH] Fix http://llvm.org/bugs/show_bug.cgi?id=2106. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47768 91177308-0d34-0410-b5e6-96231b3b80d8 --- Parse/ParseObjc.cpp | 2 +- Sema/SemaDeclObjC.cpp | 6 ++++++ include/clang/Basic/DiagnosticKinds.def | 4 ++++ test/Sema/missing-method-context.m | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/Sema/missing-method-context.m diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 24d6309905..816d2bf6a3 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -1240,7 +1240,7 @@ Parser::DeclTy *Parser::ParseObjCMethodDefinition() { // We should have an opening brace now. if (Tok.isNot(tok::l_brace)) { - Diag(Tok, diag::err_expected_fn_body); + Diag(Tok, diag::err_expected_method_body); // Skip over garbage, until we get to '{'. Don't eat the '{'. SkipUntil(tok::l_brace, true, true); diff --git a/Sema/SemaDeclObjC.cpp b/Sema/SemaDeclObjC.cpp index 267a9ef789..04ce426dec 100644 --- a/Sema/SemaDeclObjC.cpp +++ b/Sema/SemaDeclObjC.cpp @@ -807,6 +807,12 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames, AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind, bool isVariadic) { + + // Make sure we can establish a context for the method. + if (!ClassDecl) { + Diag(MethodLoc, diag::error_missing_method_context); + return 0; + } llvm::SmallVector Params; for (unsigned i = 0; i < Sel.getNumArgs(); i++) { diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 3d0a3f8815..2ebe72ed55 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -356,6 +356,8 @@ DIAG(err_function_declared_typedef, ERROR, "function definition declared 'typedef'") DIAG(err_expected_fn_body, ERROR, "expected function body after function declarator") +DIAG(err_expected_method_body, ERROR, + "expected method body") DIAG(err_expected_after_declarator, ERROR, "expected '=', ',', ';', 'asm', or '__attribute__' after declarator") DIAG(err_expected_statement, ERROR, @@ -484,6 +486,8 @@ DIAG(err_toomany_element_decls, ERROR, "Only one element declaration is allowed") DIAG(warn_expected_implementation, WARNING, "@end must appear in an @implementation context") +DIAG(error_missing_method_context, ERROR, + "missing context for method declaration") DIAG(error_bad_receiver_type, ERROR, "bad receiver type '%0'") diff --git a/test/Sema/missing-method-context.m b/test/Sema/missing-method-context.m new file mode 100644 index 0000000000..20437b70ec --- /dev/null +++ b/test/Sema/missing-method-context.m @@ -0,0 +1,4 @@ +// RUN: clang %s -verify -fsyntax-only +- (void)compilerTestAgainst; // expected-error {{missing context for method declaration}} + +void xx(); // expected-error {{expected method body}} -- 2.40.0