summaryrefslogtreecommitdiffstats
path: root/test/SemaObjC/method-typecheck-3.m
diff options
context:
space:
mode:
authorDavid Chisnall <csdavec@swan.ac.uk>2010-10-25 17:23:52 +0000
committerDavid Chisnall <csdavec@swan.ac.uk>2010-10-25 17:23:52 +0000
commite8a2d4c32cb2a7840bd91c9cf9b7838ee3f47dc3 (patch)
tree1a16ba859f7fbc1b859361e0cc3efeffb1fee477 /test/SemaObjC/method-typecheck-3.m
parent428edafa9eb80e01dd40aab31d4166a787a741e1 (diff)
Only warn for mismatched types in Objective-C methods when they are incompatible, not when they are simply different. Now we test whether the difference in types breaks the principle of substitutability, rather than whether they are different.
A common idiom in Objective-C is to provide a definition of a method in a subclass that returns a more-specified version of an object than the superclass. This does not violate the principle of substitutability, because you can always use the object returned by the subclass anywhere that you could use the type returned by the superclass. It was, however, generating warnings with clang, leading people to believe that semantically correct code was incorrect and requiring less accurate type specification and explicit down-casts (neither of which is a good thing to encourage). This change ensures that any method definition has parameter and return types that make it accept anything that something conforming to the declaration may pass and return something that the caller will expect, but allows stricter definitions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117271 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaObjC/method-typecheck-3.m')
-rw-r--r--test/SemaObjC/method-typecheck-3.m21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/SemaObjC/method-typecheck-3.m b/test/SemaObjC/method-typecheck-3.m
new file mode 100644
index 0000000000..629889c3ad
--- /dev/null
+++ b/test/SemaObjC/method-typecheck-3.m
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@interface A
+- (id)obj;
+- (A*)a;
+- (void)takesA: (A*)a; // expected-note {{previous definition is here}}
+- (void)takesId: (id)a; // expected-note {{previous definition is here}}
+@end
+
+
+@interface B : A
+@end
+
+@implementation B
+- (B*)obj {return self;}
+- (B*)a { return self;}
+- (void)takesA: (B*)a // expected-warning {{conflicting parameter types in implementation of 'takesA:'}}
+{}
+- (void)takesId: (B*)a // expected-warning {{conflicting parameter types in implementation of 'takesId:'}}
+{}
+@end