const IdentifierInfo *Name);
void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
+ void CompareMethodParamsInBaseAndSuper(Decl *IDecl,
+ ObjCMethodDecl *MethodDecl,
+ bool IsInstance);
+
void MergeProtocolPropertiesIntoClass(Decl *CDecl,
DeclPtrTy MergeProtocols);
AddInstanceMethodToGlobalPool(SetterMethod);
}
+void Sema::CompareMethodParamsInBaseAndSuper(Decl *ClassDecl,
+ ObjCMethodDecl *Method,
+ bool IsInstance) {
+ if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ClassDecl))
+ while (ObjCInterfaceDecl *SD = ID->getSuperClass()) {
+ if (ObjCMethodDecl *SuperMethodDecl =
+ SD->lookupMethod(Method->getSelector(), IsInstance)) {
+ ObjCMethodDecl::param_iterator ParamI = Method->param_begin(),
+ E = Method->param_end();
+ ObjCMethodDecl::param_iterator PrevI =
+ SuperMethodDecl->param_begin();
+ for (; ParamI != E; ++ParamI, ++PrevI) {
+ assert(PrevI != SuperMethodDecl->param_end() && "Param mismatch");
+ QualType T1 = Context.getCanonicalType((*ParamI)->getType());
+ QualType T2 = Context.getCanonicalType((*PrevI)->getType());
+ if (T1 != T2) {
+ AssignConvertType ConvTy = CheckAssignmentConstraints(T1, T2);
+ if (ConvTy == Incompatible || ConvTy == IncompatiblePointer) {
+ Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
+ << T1 << T2;
+ Diag(SuperMethodDecl->getLocation(),
+ diag::note_previous_declaration);
+ return;
+ }
+ }
+ }
+ }
+ ID = SD;
+ }
+}
+
// Note: For class/category implemenations, allMethods/allProperties is
// always null.
void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl,
InsMap[Method->getSelector()] = Method;
/// The following allows us to typecheck messages to "id".
AddInstanceMethodToGlobalPool(Method);
+ CompareMethodParamsInBaseAndSuper(ClassDecl, Method, true);
}
}
else {
ClsMap[Method->getSelector()] = Method;
/// The following allows us to typecheck messages to "Class".
AddFactoryMethodToGlobalPool(Method);
+ CompareMethodParamsInBaseAndSuper(ClassDecl, Method, false);
}
}
}
--- /dev/null
+// RUN: clang-cc -fsyntax-only -verify %s
+
+@interface Root
+-(void) method_r: (char)ch : (float*)f1 : (int*) x; // expected-note {{previous declaration is here}}
+@end
+
+@class Sub;
+
+@interface Base : Root
+-(void) method: (int*) x; // expected-note {{previous declaration is here}}
+-(void) method1: (Base*) x; // expected-note {{previous declaration is here}}
+-(void) method2: (Sub*) x;
++ method3: (int)x1 : (Base *)x2 : (float)x3; // expected-note {{previous declaration is here}}
++ mathod4: (id)x1;
+@end
+
+struct A {
+ int x,y,z;
+};
+
+@interface Sub : Base
+-(void) method: (struct A*) a; // expected-warning {{method parameter type 'struct A *' does not match super class method parameter type 'int *'}}
+-(void) method1: (Sub*) x; // expected-warning {{method parameter type 'Sub *' does not match super class method parameter type 'Base *'}}
+-(void) method2: (Base*) x; // no need to warn. At call point we warn if need be.
++ method3: (int)x1 : (Sub *)x2 : (float)x3; // expected-warning {{method parameter type 'Sub *' does not match super class method parameter type 'Base *'}}
++ mathod4: (Base*)x1;
+-(void) method_r: (char)ch : (float*)f1 : (Sub*) x; // expected-warning {{method parameter type 'Sub *' does not match super class method parameter type 'int *'}}
+@end
+
+void f(Base *base, Sub *sub) {
+ int x;
+ [base method:&x]; // warn. if base is actually 'Sub' it will use -[Sub method] with wrong arguments
+
+ Base *b;
+ [base method1:b]; // if base is actuall 'Sub' it will use [Sub method1] with wrong argument.
+
+ [base method2:b]; // expected-warning {{}}
+
+ Sub *s;
+ [base method2:s]; // if base is actually 'Sub' OK. Either way OK.
+
+}
+
+
+
+