]> granicus.if.org Git - clang/commitdiff
objective-C: warn if selector has nothing but bare
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 11 Sep 2012 21:27:45 +0000 (21:27 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 11 Sep 2012 21:27:45 +0000 (21:27 +0000)
':' in its name. // rdar://8366823

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

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseObjc.cpp
test/SemaObjC/warn-missing-selector-arg-name.m

index 5f8e8aa3ac866666a951df4650d437c3d5a0fe0f..ccdea4aabbb313667c4ffd1142fa3a13dad9a9ad 100644 (file)
@@ -361,6 +361,9 @@ def warn_missing_argument_name : Warning<
   "no parameter name in the middle of a selector"
   " may result in incomplete selector name">,
   InGroup<DiagGroup<"missing-argument-name-in-selector">>, DefaultIgnore;
+def warn_selector_with_bare_colon : Warning<
+  "selector has only bare colons in its name">,
+  InGroup<DiagGroup<"selector-with-bare-colons">>, DefaultIgnore;
 def note_missing_argument_name : Note<
   "did you mean %0 as the selector name">;
 
index 6d5f35a7993772f91b8744994a8b0a4455d6c07f..2bcb7a786ab4cfa98183f05b63e19ef5da712e1b 100644 (file)
@@ -1032,6 +1032,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
 
   AttributePool allParamAttrs(AttrFactory);
   bool warnSelectorName = false;
+  bool warnHasNoName = true;
   while (1) {
     ParsedAttributes paramAttrs(AttrFactory);
     Sema::ObjCArgInfo ArgInfo;
@@ -1109,7 +1110,8 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
       Diag(Tok, diag::warn_missing_argument_name); // missing argument name.
       warnSelectorName = true;
     }
-    
+    else
+      warnHasNoName = false;
     // We have a selector or a colon, continue parsing.
   }
 
@@ -1150,8 +1152,11 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
   
   Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
                                                    &KeyIdents[0]);
-  if (warnSelectorName)
+  if (warnSelectorName) {
+    if (warnHasNoName)
+      Diag(mLoc, diag::warn_selector_with_bare_colon);
     Diag(mLoc, diag::note_missing_argument_name) << Sel.getAsString();
+  }
   
   Decl *Result
        = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(),
index 97bcd0db91df07b0b6a2ac1c704251c151b0ba74..3d2a75a1eb5a4289a86ed93f4702917ce9addce4 100644 (file)
@@ -1,11 +1,15 @@
-// RUN: %clang_cc1  -fsyntax-only -verify -Wno-objc-root-class -Wmissing-argument-name-in-selector %s
-// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class -Wmissing-argument-name-in-selector %s
+// RUN: %clang_cc1  -fsyntax-only -verify -Wselector-with-bare-colons -Wmissing-argument-name-in-selector %s
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wselector-with-bare-colons -Wmissing-argument-name-in-selector %s
+// rdar://8366823
 // rdar://12263549
 
 @interface Super @end
 @interface INTF : Super
+- (void) MMM;
+- (void)bar:(id)b;
 -(void) Name1:(id)Arg1 Name2:(id)Arg2; // Name1:Name2:
 -(void) Name1:(id) Name2:(id)Arg2; // expected-warning {{no parameter name in the middle of a selector may result in incomplete selector name}} \
+                                   // expected-warning {{selector has only bare colons in its name}} \
                                    // expected-note {{did you mean Name1:: as the selector name}}
 -(void) Name1:(id)Arg1 Name2:(id)Arg2 Name3:(id)Arg3; // Name1:Name2:Name3:
 -(void) Name1:(id)Arg1 Name2:(id) Name3:(id)Arg3; // expected-warning {{no parameter name in the middle of a selector may result in incomplete selector name}} \
 @end
 
 @implementation INTF
+- (void) MMM{}
+- (void)bar:(id)b{}
 -(void) Name1:(id)Arg1 Name2:(id)Arg2{}
 -(void) Name1:(id) Name2:(id)Arg2 {} // expected-warning {{no parameter name in the middle of a selector may result in incomplete selector name}} \
+                                     // expected-warning {{selector has only bare colons in its name}} \
                                     // expected-note {{did you mean Name1:: as the selector name}}
 -(void) Name1:(id)Arg1 Name2:(id)Arg2 Name3:(id)Arg3 {}
 -(void) Name1:(id)Arg1 Name2:(id) Name3:(id)Arg3 {} // expected-warning {{no parameter name in the middle of a selector may result in incomplete selector name}} \