]> granicus.if.org Git - clang/commitdiff
Warn (as gcc does) when @end does not close anything.
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 10 Jan 2008 17:58:07 +0000 (17:58 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 10 Jan 2008 17:58:07 +0000 (17:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45834 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseObjc.cpp
include/clang/Basic/DiagnosticKinds.def
test/Parser/objc-missing-impl.m [new file with mode: 0644]

index 989f1dce1743948d4dbce8c0675d56f2574797f6..34694ef5c5bbc54af7a3bbfff7e4145ba3495644 100644 (file)
@@ -991,13 +991,10 @@ Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
   assert(Tok.isObjCAtKeyword(tok::objc_end) &&
          "ParseObjCAtEndDeclaration(): Expected @end");
   ConsumeToken(); // the "end" identifier
-  if (ObjCImpDecl) {
-    // Checking is not necessary except that a parse error might have caused
-    // @implementation not to have been parsed to completion and ObjCImpDecl 
-    // could be 0.
+  if (ObjCImpDecl)
     Actions.ActOnAtEnd(atLoc, ObjCImpDecl);
-  }
-
+  else
+    Diag(atLoc, diag::warn_expected_implementation); // missing @implementation
   return ObjCImpDecl;
 }
 
index 289f770ec69b47bd4389a13fb6c65cb82de34693..f041a3a47b9a1f64102afb5290165cd95e2dc061 100644 (file)
@@ -478,6 +478,8 @@ DIAG(err_selector_element_type, ERROR,
      "selector element is not of valid object type (its type is '%0')")
 DIAG(err_toomany_element_decls, ERROR,
      "Only one element declaration is allowed")
+DIAG(warn_expected_implementation, WARNING,
+     "‘@end’ must appear in an @implementation context")
 
 //===----------------------------------------------------------------------===//
 // Semantic Analysis
diff --git a/test/Parser/objc-missing-impl.m b/test/Parser/objc-missing-impl.m
new file mode 100644 (file)
index 0000000..062130d
--- /dev/null
@@ -0,0 +1,2 @@
+// RUN: clang -fsyntax-only -verify %s
+@end // expected-warning {{‘@end’ must appear in an @implementation context}}