forked from OSchip/llvm-project
objc: put out more coherent warning when method definition
attributes don't match its declaration. // rdar://10529259. llvm-svn: 145872
This commit is contained in:
parent
34a7c6dfd7
commit
56f326e7f2
|
@ -5025,7 +5025,7 @@ def error_protected_ivar_access : Error<"instance variable %0 is protected">,
|
|||
AccessControl;
|
||||
def warn_maynot_respond : Warning<"%0 may not respond to %1">;
|
||||
def warn_attribute_method_def : Warning<
|
||||
"method attribute can only be specified on method declarations">,
|
||||
"attributes on method implementation and its declaration must match">,
|
||||
InGroup<DiagGroup<"mismatched-method-attributes">>;
|
||||
def ext_typecheck_base_super : Warning<
|
||||
"method parameter type %0 does not match "
|
||||
|
|
|
@ -2712,8 +2712,10 @@ Decl *Sema::ActOnMethodDeclaration(
|
|||
IMD = IDecl->lookupMethod(ObjCMethod->getSelector(),
|
||||
ObjCMethod->isInstanceMethod());
|
||||
if (ObjCMethod->hasAttrs() &&
|
||||
containsInvalidMethodImplAttribute(IMD, ObjCMethod->getAttrs()))
|
||||
containsInvalidMethodImplAttribute(IMD, ObjCMethod->getAttrs())) {
|
||||
Diag(EndLoc, diag::warn_attribute_method_def);
|
||||
Diag(IMD->getLocation(), diag::note_method_declared_at);
|
||||
}
|
||||
} else {
|
||||
cast<DeclContext>(ClassDecl)->addDecl(ObjCMethod);
|
||||
}
|
||||
|
|
|
@ -13,23 +13,45 @@
|
|||
@interface INTF
|
||||
- (int) foo1: (int)arg1 __attribute__((deprecated));
|
||||
|
||||
- (int) foo: (int)arg1;
|
||||
- (int) foo: (int)arg1; // expected-note {{method declared here}}
|
||||
|
||||
- (int) foo2: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable));
|
||||
- (int) foo2: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{method declared here}}
|
||||
- (int) foo3: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)) __attribute__((ns_consumes_self));
|
||||
@end
|
||||
|
||||
@implementation INTF
|
||||
- (int) foo: (int)arg1 __attribute__((deprecated)){ // expected-warning {{method attribute can only be specified}}
|
||||
- (int) foo: (int)arg1 __attribute__((deprecated)){ // expected-warning {{attributes on method implementation and its declaration must match}}
|
||||
return 10;
|
||||
}
|
||||
- (int) foo1: (int)arg1 {
|
||||
return 10;
|
||||
}
|
||||
- (int) foo2: (int)arg1 __attribute__((deprecated)) { // expected-warning {{method attribute can only be specified}}
|
||||
- (int) foo2: (int)arg1 __attribute__((deprecated)) { // expected-warning {{attributes on method implementation and its declaration must match}}
|
||||
return 10;
|
||||
}
|
||||
- (int) foo3: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)) __attribute__((ns_consumes_self)) {return 0; }
|
||||
- (void) dep __attribute__((deprecated)) { } // OK private methodn
|
||||
@end
|
||||
|
||||
|
||||
// rdar://10529259
|
||||
#define IBAction void)__attribute__((ibaction)
|
||||
|
||||
@interface Foo
|
||||
- (void)doSomething1:(id)sender;
|
||||
- (void)doSomething2:(id)sender; // expected-note {{method declared here}}
|
||||
@end
|
||||
|
||||
@implementation Foo
|
||||
- (void)doSomething1:(id)sender{}
|
||||
- (void)doSomething2:(id)sender{}
|
||||
@end
|
||||
|
||||
@interface Bar : Foo
|
||||
- (IBAction)doSomething1:(id)sender;
|
||||
@end
|
||||
@implementation Bar
|
||||
- (IBAction)doSomething1:(id)sender {}
|
||||
- (IBAction)doSomething2:(id)sender {} // expected-warning {{attributes on method implementation and its declaration must match}}
|
||||
- (IBAction)doSomething3:(id)sender {}
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue