]> granicus.if.org Git - clang/commitdiff
Issue warning if method body starts with a semicolon.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 20 Oct 2009 16:39:13 +0000 (16:39 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 20 Oct 2009 16:39:13 +0000 (16:39 +0000)
Fixes
<rdar://problem/7308503> clang should disallow the trailing semicolon in method definitions

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84645 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseObjc.cpp
test/SemaObjC/objc-string-constant.m
test/SemaObjC/try-catch.m

index 6971df50cb551ed883f6d36d82e3e1583e4d9e60..afd413fcab5e0b99ba4688f2e2d2a8f5845989bd 100644 (file)
@@ -201,6 +201,9 @@ def warn_expected_implementation : Warning<
   "@end must appear in an @implementation context">;
 def error_property_ivar_decl : Error<
   "property synthesize requires specification of an ivar">;
+def warn_semicolon_before_method_nody : Warning<
+  "semicolon at start of method definition is ignored">,
+  InGroup<DiagGroup<"semicolon-at-method-body">>;
 
 def err_expected_field_designator : Error<
   "expected a field designator, such as '.field = 4'">;
index 158cf1b49b4f7fc4330572c3fd457a965ee9d895..2e0cd6d0d932970c3d4543379ebad74e682a9161 100644 (file)
@@ -1371,8 +1371,11 @@ Parser::DeclPtrTy Parser::ParseObjCMethodDefinition() {
                                         "parsing Objective-C method");
 
   // parse optional ';'
-  if (Tok.is(tok::semi))
+  if (Tok.is(tok::semi)) {
+    if (ObjCImpDecl)
+      Diag(Tok, diag::warn_semicolon_before_method_nody);
     ConsumeToken();
+  }
 
   // We should have an opening brace now.
   if (Tok.isNot(tok::l_brace)) {
index 98239229a2c7f2ef4a3e616f6ac3f98c215739e6..a4d83854c1978c7f407ff74b3ef560dee200ddeb 100644 (file)
@@ -29,7 +29,7 @@
 @end
 
 @implementation Subclass
-- (NSString *)token;
+- (NSString *)token;   // expected-warning {{semicolon at start of method definition is ignored}}
 {
   NSMutableString *result = nil;
 
index 076eff542968486ec5ee8a6bd785fd2a19c4404b..453d80fd599656d1d3943fcdfef00600250b733b 100644 (file)
@@ -30,7 +30,7 @@ typedef struct _NSZone NSZone;
 @end
 
 @implementation XCRefactoringTransformation
-- (NSDictionary *)setUpInfoForTransformKey:(NSString *)transformKey outError:(NSError **)outError; {
+- (NSDictionary *)setUpInfoForTransformKey:(NSString *)transformKey outError:(NSError **)outError {
     @try {}
     // the exception name is optional (weird)
     @catch (NSException *) {}