[cfe-commits] r163634 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseObjc.cpp test/SemaObjC/warn-missing-selector-arg-name.m
Fariborz Jahanian
fjahanian at apple.com
Tue Sep 11 10:24:27 PDT 2012
Author: fjahanian
Date: Tue Sep 11 12:24:26 2012
New Revision: 163634
URL: http://llvm.org/viewvc/llvm-project?rev=163634&view=rev
Log:
objective-C: warn under a flag if missing argument
name results in unintended selector name.
// rdar://12263549
Added:
cfe/trunk/test/SemaObjC/warn-missing-selector-arg-name.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseObjc.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=163634&r1=163633&r2=163634&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Sep 11 12:24:26 2012
@@ -357,6 +357,12 @@
def warn_cstyle_param : Warning<
"use of C-style parameters in Objective-C method declarations"
" is deprecated">, InGroup<DeprecatedDeclarations>;
+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 note_missing_argument_name : Note<
+ "did you mean %0 as the selector name">;
let CategoryName = "ARC Parse Issue" in {
def err_arc_bridge_retain : Error<
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=163634&r1=163633&r2=163634&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Sep 11 12:24:26 2012
@@ -1031,7 +1031,7 @@
Scope::FunctionPrototypeScope|Scope::DeclScope);
AttributePool allParamAttrs(AttrFactory);
-
+ bool warnSelectorName = false;
while (1) {
ParsedAttributes paramAttrs(AttrFactory);
Sema::ObjCArgInfo ArgInfo;
@@ -1100,8 +1100,16 @@
// Check for another keyword selector.
SelIdent = ParseObjCSelectorPiece(selLoc);
- if (!SelIdent && Tok.isNot(tok::colon))
- break;
+ if (!SelIdent) {
+ if (Tok.isNot(tok::colon))
+ break;
+ // parameter name was not followed with selector name; as in:
+ // - (void) Meth: (id) Name:(id)Arg2; Issue a warning as user
+ // might have meant: - (void) Meth: (id)Arg1 Name:(id)Arg2;
+ Diag(Tok, diag::warn_missing_argument_name); // missing argument name.
+ warnSelectorName = true;
+ }
+
// We have a selector or a colon, continue parsing.
}
@@ -1142,6 +1150,9 @@
Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
&KeyIdents[0]);
+ if (warnSelectorName)
+ Diag(mLoc, diag::note_missing_argument_name) << Sel.getAsString();
+
Decl *Result
= Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(),
mType, DSRet, ReturnType,
Added: cfe/trunk/test/SemaObjC/warn-missing-selector-arg-name.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-missing-selector-arg-name.m?rev=163634&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-missing-selector-arg-name.m (added)
+++ cfe/trunk/test/SemaObjC/warn-missing-selector-arg-name.m Tue Sep 11 12:24:26 2012
@@ -0,0 +1,22 @@
+// 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
+// rdar://12263549
+
+ at interface Super @end
+ at interface INTF : Super
+-(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-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}} \
+ // expected-note {{did you mean Name1:Name2:: as the selector name}}
+ at end
+
+ at implementation INTF
+-(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-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}} \
+ // expected-note {{did you mean Name1:Name2:: as the selector name}}
+ at end
More information about the cfe-commits
mailing list