1 // RUN: %clang_cc1 -verify -Wused-but-marked-unused -Wno-objc-protocol-method-implementation -Wunused -Wunused-parameter -fsyntax-only -Wno-objc-root-class %s
3 int printf(const char *, ...);
9 @implementation Greeter
10 + (void) hello { printf("Hello, World!\n"); }
18 @interface NSObject @end
19 @interface NSString : NSObject
24 @"pointless example call for test purposes".length; // expected-warning {{property access result unused - getters should not be used for side effects}}
28 - (int)meth: (int)x : (int)y : (int)z ;
32 - (int) meth: (int)x: // expected-warning {{'x' used as the name of the previous parameter rather than as part of the selector}} \
33 // expected-note {{introduce a parameter name to make 'x' part of the selector}} \
34 // expected-note {{or insert whitespace before ':' to use 'x' as parameter name and have an empty entry in the selector}}
36 (int)y: // expected-warning {{'y' used as the name of the previous parameter rather than as part of the selector}} \
37 // expected-note {{introduce a parameter name to make 'y' part of the selector}} \
38 // expected-note {{or insert whitespace before ':' to use 'y' as parameter name and have an empty entry in the selector}}
39 (int) __attribute__((unused))z { return x; }
42 //===------------------------------------------------------------------------===
43 // The next test shows how clang accepted attribute((unused)) on ObjC
44 // instance variables, which GCC does not.
45 //===------------------------------------------------------------------------===
47 #if __has_feature(attribute_objc_ivar_unused)
48 #define UNUSED_IVAR __attribute__((unused))
50 #error __attribute__((unused)) not supported on ivars
53 @interface TestUnusedIvar {
54 id y __attribute__((unused)); // no-warning
55 id x UNUSED_IVAR; // no-warning
59 static NSString *x = @"hi"; // expected-warning {{unused variable 'x'}}
61 @interface TestTransitiveUnused
62 - (void) a __attribute__((unused));
63 - (void) b __attribute__((unused));
66 @interface TestTransitiveUnused(CAT)
69 @implementation TestTransitiveUnused(CAT)
71 - (void) a { [self b]; }
74 // Test that objc_precise_lifetime suppresses
75 // unused variable warnings.
76 extern void rdar15596883_foo(void);
77 void rdar15596883(id x) {
78 __attribute__((objc_precise_lifetime)) id y = x; // no-warning
82 @interface PropertyObject : NSObject
87 @property int property;
90 void test3(PropertyObject *o)
92 [o length]; // No warning. property name used in direct method call.
97 [o length]; // No warning.
102 [p property]; // No warning. property name used in direct method call.
106 @property (nonatomic, retain, setter=setOrCreateGroup:, getter=getOrCreateGroup) id group;
109 @implementation Model {
113 [self getOrCreateGroup];
114 self.getOrCreateGroup; // expected-warning {{property access result unused - getters should not be used for side effects}}
115 self.group; // expected-warning {{property access result unused - getters should not be used for side effects}}
116 self.group = (void*)0;
117 [self setOrCreateGroup : ((void*)0)];
120 - (id)getOrCreateGroup {