]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaObjC/unused.m
Vendor import of clang trunk r161861:
[FreeBSD/FreeBSD.git] / test / SemaObjC / unused.m
1 // RUN: %clang_cc1 -verify -Wunused -Wunused-parameter -fsyntax-only -Wno-objc-root-class %s
2
3 int printf(const char *, ...);
4
5 @interface Greeter
6 + (void) hello;
7 @end
8
9 @implementation Greeter
10 + (void) hello { printf("Hello, World!\n"); }
11 @end
12
13 int test1(void) {
14   [Greeter hello];
15   return 0;
16 }
17
18 @interface NSObject @end
19 @interface NSString : NSObject 
20 - (int)length;
21 @end
22
23 void test2() {
24   @"pointless example call for test purposes".length; // expected-warning {{property access result unused - getters should not be used for side effects}}
25 }
26
27 @interface foo
28 - (int)meth: (int)x: (int)y: (int)z ;
29 @end
30
31 @implementation foo
32 - (int) meth: (int)x: 
33 (int)y: // expected-warning{{unused}} 
34 (int) __attribute__((unused))z { return x; }
35 @end
36
37 //===------------------------------------------------------------------------===
38 // The next test shows how clang accepted attribute((unused)) on ObjC
39 // instance variables, which GCC does not.
40 //===------------------------------------------------------------------------===
41
42 #if __has_feature(attribute_objc_ivar_unused)
43 #define UNUSED_IVAR __attribute__((unused))
44 #else
45 #error __attribute__((unused)) not supported on ivars
46 #endif
47
48 @interface TestUnusedIvar {
49   id y __attribute__((unused)); // no-warning
50   id x UNUSED_IVAR; // no-warning
51 }
52 @end
53
54 // rdar://10777111
55 static NSString *x = @"hi"; // expected-warning {{unused variable 'x'}}