[cfe-commits] r68879 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/comptypes-a.m test/SemaObjC/method-conflict.m test/SemaObjC/method-def-1.m test/SemaObjC/method-typecheck-1.m test/SemaObjC/property-typecheck-1.m
Chris Lattner
sabre at nondot.org
Sat Apr 11 12:58:42 PDT 2009
Author: lattner
Date: Sat Apr 11 14:58:42 2009
New Revision: 68879
URL: http://llvm.org/viewvc/llvm-project?rev=68879&view=rev
Log:
improve the 'conflicting types' diagnostics to include correct location info, now
that it is plumbed through Sema. On a file from growl, we used to emit:
t.mi:107059:1: warning: conflicting types for 'removePluginHandler:forPluginTypes:'
- (void) removePluginHandler:(id <GrowlPluginHandler>)handler forPluginTypes:(NSSet *)extensions {
^
t.mi:105280:1: note: previous definition is here
- (void) removePluginHandler:(id <NSObject>)handler forPluginTypes:(NSSet *)types;
^
now we produce:
t.mi:107059:55: warning: conflicting parameter types in implementation of 'removePluginHandler:forPluginTypes:': 'id<NSObject>' vs 'id<GrowlPluginHandler>'
- (void) removePluginHandler:(id <GrowlPluginHandler>)handler forPluginTypes:(NSSet *)extensions {
^
t.mi:105280:45: note: previous definition is here
- (void) removePluginHandler:(id <NSObject>)handler forPluginTypes:(NSSet *)types;
^
We still don't have proper loc info for properties, hence the FIXME.
rdar://6782494
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/comptypes-a.m
cfe/trunk/test/SemaObjC/method-conflict.m
cfe/trunk/test/SemaObjC/method-def-1.m
cfe/trunk/test/SemaObjC/method-typecheck-1.m
cfe/trunk/test/SemaObjC/property-typecheck-1.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=68879&r1=68878&r2=68879&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Apr 11 14:58:42 2009
@@ -158,7 +158,13 @@
"inconsistent number of instance variables specified">;
def warn_incomplete_impl : Warning<"incomplete implementation">;
def warn_undef_method_impl : Warning<"method definition for %0 not found">;
-def warn_conflicting_types : Warning<"conflicting types for %0">;
+
+def warn_conflicting_ret_types : Warning<
+ "conflicting return type in implementation of %0: %1 vs %2">;
+
+def warn_conflicting_param_types : Warning<
+ "conflicting parameter types in implementation of %0: %1 vs %2">;
+
def warn_multiple_method_decl : Warning<"multiple methods named %0 found">;
def err_accessor_property_type_mismatch : Error<
"type of property %0 does not match type of accessor %1">;
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=68879&r1=68878&r2=68879&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sat Apr 11 14:58:42 2009
@@ -763,25 +763,28 @@
void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
ObjCMethodDecl *IntfMethodDecl) {
- bool err = false;
if (!Context.typesAreCompatible(IntfMethodDecl->getResultType(),
- ImpMethodDecl->getResultType()))
- err = true;
- else
- for (ObjCMethodDecl::param_iterator IM=ImpMethodDecl->param_begin(),
- IF = IntfMethodDecl->param_begin(), EM = ImpMethodDecl->param_end();
- IM != EM; ++IM, ++IF) {
- if (!Context.typesAreCompatible((*IF)->getType(), (*IM)->getType())) {
- err = true;
- break;
- }
- }
-
- if (err) {
- Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_types)
- << ImpMethodDecl->getDeclName();
+ ImpMethodDecl->getResultType())) {
+ Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_ret_types)
+ << ImpMethodDecl->getDeclName() << IntfMethodDecl->getResultType()
+ << ImpMethodDecl->getResultType();
Diag(IntfMethodDecl->getLocation(), diag::note_previous_definition);
}
+
+ for (ObjCMethodDecl::param_iterator IM = ImpMethodDecl->param_begin(),
+ IF = IntfMethodDecl->param_begin(), EM = ImpMethodDecl->param_end();
+ IM != EM; ++IM, ++IF) {
+ if (Context.typesAreCompatible((*IF)->getType(), (*IM)->getType()))
+ continue;
+
+ Diag((*IM)->getLocation(), diag::warn_conflicting_param_types)
+ << ImpMethodDecl->getDeclName() << (*IF)->getType()
+ << (*IM)->getType();
+ SourceLocation Loc = (*IF)->getLocation();
+ // FIXME
+ if (Loc == SourceLocation()) Loc = IntfMethodDecl->getLocation();
+ Diag(Loc, diag::note_previous_definition);
+ }
}
/// isPropertyReadonly - Return true if property is readonly, by searching
Modified: cfe/trunk/test/SemaObjC/comptypes-a.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/comptypes-a.m?rev=68879&r1=68878&r2=68879&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/comptypes-a.m (original)
+++ cfe/trunk/test/SemaObjC/comptypes-a.m Sat Apr 11 14:58:42 2009
@@ -23,7 +23,9 @@
@implementation TedWantsToVerifyObjCDoesTheRightThing
-- compareThis:(id<PBXCompletionItem>)a withThat:(id<PBXCompletionItem>)b { // expected-warning {{conflicting types for 'compareThis:withThat:'}}
+- compareThis:(id<PBXCompletionItem>)
+ a // expected-warning {{conflicting parameter types in implementation of 'compareThis:withThat:': 'int' vs 'id<PBXCompletionItem>'}}
+ withThat:(id<PBXCompletionItem>)b {
return self;
}
Modified: cfe/trunk/test/SemaObjC/method-conflict.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-conflict.m?rev=68879&r1=68878&r2=68879&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-conflict.m (original)
+++ cfe/trunk/test/SemaObjC/method-conflict.m Sat Apr 11 14:58:42 2009
@@ -49,6 +49,6 @@
{
}
// GCC doesn't currently warn about this.
-+ (NSUInteger) compartmentsForClassifier: (id <XDSCClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec { // expected-warning {{conflicting types for 'compartmentsForClassifier:withSpecification:'}}
++ (NSUInteger) compartmentsForClassifier: (id <XDSCClassifier>) classifier withSpecification: (XDSCDisplaySpecification *) displaySpec { // expected-warning {{conflicting parameter types in implementation of 'compartmentsForClassifier:withSpecification:': 'id<XDUMLClassifier>' vs 'id<XDSCClassifier>'}}
}
@end
Modified: cfe/trunk/test/SemaObjC/method-def-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-def-1.m?rev=68879&r1=68878&r2=68879&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-def-1.m (original)
+++ cfe/trunk/test/SemaObjC/method-def-1.m Sat Apr 11 14:58:42 2009
@@ -17,5 +17,24 @@
@implementation MyClass
- (void)myMethod { }
- (vid)myMethod2 { } // expected-error {{expected a type}}
+
+ at end
+
+
+ at protocol proto;
+ at protocol NSObject;
+
+//@protocol GrowlPluginHandler <NSObject> @end
+
+
+ at interface SomeClass2
+- (int)myMethod1: (id<proto>)
+arg; // expected-note {{previous definition is here}}
@end
+ at implementation SomeClass2
+- (int)myMethod1: (id<NSObject>)
+ arg { // expected-warning {{conflicting parameter types in implementation of 'myMethod1:': 'id<proto>' vs 'id<NSObject>'}}
+
+}
+ at end
Modified: cfe/trunk/test/SemaObjC/method-typecheck-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-typecheck-1.m?rev=68879&r1=68878&r2=68879&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-typecheck-1.m (original)
+++ cfe/trunk/test/SemaObjC/method-typecheck-1.m Sat Apr 11 14:58:42 2009
@@ -7,29 +7,31 @@
@end
@implementation A
--(void) setMoo: (float) x {} // expected-warning {{conflicting types for 'setMoo:'}}
-- (char) setMoo1: (int) x {} // expected-warning {{conflicting types for 'setMoo1:'}}
+-(void) setMoo: (float) x {} // expected-warning {{conflicting parameter types in implementation of 'setMoo:': 'int' vs 'float'}}
+- (char) setMoo1: (int) x {} // expected-warning {{conflicting return type in implementation of 'setMoo1:': 'int' vs 'char'}}
- (int) setOk : (int) x : (double) d {}
@end
@interface C
-+ (void) cMoo: (int) x; // expected-note {{previous definition is here}}
++ (void) cMoo: (int) x; // expected-note 2 {{previous definition is here}}
@end
@implementation C
-+(float) cMoo: (float) x {} // expected-warning {{conflicting types for 'cMoo:'}}
++(float) cMoo: // expected-warning {{conflicting return type in implementation of 'cMoo:': 'void' vs 'float'}}
+ (float) x {} // expected-warning {{conflicting parameter types in implementation of 'cMoo:': 'int' vs 'float'}}
@end
@interface A(CAT)
-- (void) setCat: (int) x; // expected-note {{previous definition is here}}
+- (void) setCat: (int) x; // expected-note 2 {{previous definition is here}}
+ (void) cCat: (int) x; // expected-note {{previous definition is here}}
@end
@implementation A(CAT)
--(float) setCat: (float) x {} // expected-warning {{conflicting types for 'setCat:'}}
-+ (int) cCat: (int) x {} // expected-warning {{conflicting types for 'cCat:'}}
+-(float) setCat: // expected-warning {{conflicting return type in implementation of 'setCat:': 'void' vs 'float'}}
+(float) x {} // expected-warning {{conflicting parameter types in implementation of 'setCat:': 'int' vs 'float'}}
++ (int) cCat: (int) x {} // expected-warning {{conflicting return type in implementation of 'cCat:': 'void' vs 'int'}}
@end
Modified: cfe/trunk/test/SemaObjC/property-typecheck-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-typecheck-1.m?rev=68879&r1=68878&r2=68879&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-typecheck-1.m (original)
+++ cfe/trunk/test/SemaObjC/property-typecheck-1.m Sat Apr 11 14:58:42 2009
@@ -13,7 +13,7 @@
-(int) moo {
return 0;
}
--(void) setMoo: (float) x { // expected-warning {{conflicting types for 'setMoo:'}}
+-(void) setMoo: (float) x { // expected-warning {{conflicting parameter types in implementation of 'setMoo:': 'int' vs 'float'}}
}
@end
More information about the cfe-commits
mailing list