diff options
author | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
commit | 1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch) | |
tree | c607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/gcc/testsuite/obj-c++.dg/method-lookup-1.mm | |
parent | 283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff) | |
download | toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2 toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip |
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/gcc/testsuite/obj-c++.dg/method-lookup-1.mm')
-rw-r--r-- | gcc-4.9/gcc/testsuite/obj-c++.dg/method-lookup-1.mm | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/method-lookup-1.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/method-lookup-1.mm new file mode 100644 index 000000000..47499c37c --- /dev/null +++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/method-lookup-1.mm @@ -0,0 +1,94 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, June 2011. */ +/* { dg-do compile } */ + +@class NotKnown; + +@protocol MyProtocol ++ (id) classMethod; +- (id) instanceMethod; +@end + +@protocol MyProtocol2 ++ (id) classMethod2; +- (id) instanceMethod2; +@end + +void test (Class x, Class <MyProtocol> y, id w, id <MyProtocol> z, NotKnown *a, NotKnown <MyProtocol> *b) +{ + /* "Class x" means that "x" responds to any class methods, and may + also respond to instance methods because instance methods of the + root class are class methods. */ + [x classMethod]; /* No warning here. */ + + [x instanceMethod]; /* No warning here. */ + + + /* "Class <MyProtocol> y" means that "y" responds to any class + methods specified in the protocol MyProtocol, but not to other + class or instance methods. If a class method is not found, an + instance method from the protocol may be used instead but that is + suspicious and gets a warning. */ + [y classMethod]; /* No warning here. */ + + [y instanceMethod]; /* { dg-warning "found .\\-instanceMethod. instead of .\\+instanceMethod. in protocol" } */ + + [y classMethod2]; /* { dg-warning ".\\+classMethod2. not found in protocol" } */ + + [y instanceMethod2]; /* { dg-warning ".\\+instanceMethod2. not found in protocol" } */ + + + /* If a class is specified by name, the @interface must be available + to check what it responds to. */ + [NotKnown classMethod]; /* { dg-warning ".interface of class .NotKnown. not found" } */ + + + /* "id w" means that "w" responds to anything, both class and + instance methods. */ + [w instanceMethod]; /* No warning here. */ + + [w instanceMethod2]; /* No warning here. */ + + [w classMethod]; /* No warning here. */ + + [w classMethod2]; /* No warning here. */ + + + /* "id <MyProtocol> z" means that "z" responds to any instance + methods in the protocol, but not class methods. To select class + methods, you use "Class <MyProtocol> z". */ + [z instanceMethod]; /* No warning here. */ + + [z instanceMethod2]; /* { dg-warning ".\\-instanceMethod2. not found in protocol" } */ + + [z classMethod]; /* { dg-warning ".\\-classMethod. not found in protocol" } */ + + [z classMethod2]; /* { dg-warning ".\\-classMethod2. not found in protocol" } */ + + + /* "NotKnown *a" means that "a" is an instance of NotKnown. Since + the programmer explicitly specified the class name, it must be + because they expect the compiler to do type-checking; the + @interface must be available to do this check, otherwise the + compiler does not know what "a" responds to. */ + [a instanceMethod]; /* { dg-warning ".interface of class .NotKnown. not found" } */ + + /* But, if you cast it to "id", then you're disabling type-checking + and the warnings should go away. */ + [(id)a instanceMethod]; /* No warning here. */ + + + /* "NotKnown <MyProtocol> *b" means that "a" is an instance of + NotKnown, and also implements protocol <MyProtocol>. If you send + a message that is part of the protocol, then the compiler can do + type-checking and all is fine. */ + [b instanceMethod]; + + /* But if you send a message that is not part of the protocol, then + you'll get a warning that the method can not be found in the + protocol. */ + [b instanceMethod2]; /* { dg-warning ".\\-instanceMethod2. not found in protocol" } */ + + /* But, if you cast it to "id", then you're disabling type-checking + and the warnings should go away. */ + [(id)b instanceMethod2]; /* No warning here. */ +} |