[cfe-commits] r47768 - in /cfe/trunk: Parse/ParseObjc.cpp Sema/SemaDeclObjC.cpp include/clang/Basic/DiagnosticKinds.def test/Sema/missing-method-context.m

Steve Naroff snaroff at apple.com
Fri Feb 29 13:48:07 PST 2008


Author: snaroff
Date: Fri Feb 29 15:48:07 2008
New Revision: 47768

URL: http://llvm.org/viewvc/llvm-project?rev=47768&view=rev
Log:
Fix http://llvm.org/bugs/show_bug.cgi?id=2106.


Added:
    cfe/trunk/test/Sema/missing-method-context.m
Modified:
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Sema/SemaDeclObjC.cpp
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=47768&r1=47767&r2=47768&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Fri Feb 29 15:48:07 2008
@@ -1240,7 +1240,7 @@
 
   // 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);

Modified: cfe/trunk/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDeclObjC.cpp?rev=47768&r1=47767&r2=47768&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/Sema/SemaDeclObjC.cpp Fri Feb 29 15:48:07 2008
@@ -807,6 +807,12 @@
     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<ParmVarDecl*, 16> Params;
   
   for (unsigned i = 0; i < Sel.getNumArgs(); i++) {

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=47768&r1=47767&r2=47768&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Feb 29 15:48:07 2008
@@ -356,6 +356,8 @@
      "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 @@
      "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'")
 

Added: cfe/trunk/test/Sema/missing-method-context.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/missing-method-context.m?rev=47768&view=auto

==============================================================================
--- cfe/trunk/test/Sema/missing-method-context.m (added)
+++ cfe/trunk/test/Sema/missing-method-context.m Fri Feb 29 15:48:07 2008
@@ -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}}





More information about the cfe-commits mailing list