2012-09-07 02:38:58 +08:00
|
|
|
// RUN: %clang_cc1 -verify -Wused-but-marked-unused -Wno-objc-protocol-method-implementation -Wunused -Wunused-parameter -fsyntax-only -Wno-objc-root-class %s
|
2009-11-17 16:57:36 +08:00
|
|
|
|
|
|
|
int printf(const char *, ...);
|
2007-09-27 06:06:30 +08:00
|
|
|
|
|
|
|
@interface Greeter
|
|
|
|
+ (void) hello;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Greeter
|
2010-02-25 11:26:51 +08:00
|
|
|
+ (void) hello { printf("Hello, World!\n"); }
|
2007-09-27 06:06:30 +08:00
|
|
|
@end
|
|
|
|
|
2009-08-12 04:08:52 +08:00
|
|
|
int test1(void) {
|
|
|
|
[Greeter hello];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-12 04:08:03 +08:00
|
|
|
@interface NSObject @end
|
|
|
|
@interface NSString : NSObject
|
|
|
|
- (int)length;
|
|
|
|
@end
|
|
|
|
|
2009-08-12 04:08:52 +08:00
|
|
|
void test2() {
|
2010-04-27 05:44:01 +08:00
|
|
|
@"pointless example call for test purposes".length; // expected-warning {{property access result unused - getters should not be used for side effects}}
|
2009-08-12 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
2009-08-12 04:08:52 +08:00
|
|
|
@interface foo
|
2012-09-18 07:09:59 +08:00
|
|
|
- (int)meth: (int)x : (int)y : (int)z ;
|
2009-08-12 04:08:52 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation foo
|
2012-09-18 07:09:59 +08:00
|
|
|
- (int) meth: (int)x: // expected-warning {{'x' used as the name of the previous parameter rather than as part of the selector}} \
|
|
|
|
// expected-note {{introduce a parameter name to make 'x' part of the selector}} \
|
|
|
|
// expected-note {{or insert whitespace before ':' to use 'x' as parameter name and have an empty entry in the selector}}
|
|
|
|
|
|
|
|
(int)y: // expected-warning {{unused}} expected-warning {{'y' used as the name of the previous parameter rather than as part of the selector}} \
|
|
|
|
// expected-note {{introduce a parameter name to make 'y' part of the selector}} \
|
|
|
|
// expected-note {{or insert whitespace before ':' to use 'y' as parameter name and have an empty entry in the selector}}
|
2009-08-12 04:08:52 +08:00
|
|
|
(int) __attribute__((unused))z { return x; }
|
|
|
|
@end
|
2010-02-25 11:26:51 +08:00
|
|
|
|
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
// The next test shows how clang accepted attribute((unused)) on ObjC
|
|
|
|
// instance variables, which GCC does not.
|
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
|
2010-03-06 06:43:32 +08:00
|
|
|
#if __has_feature(attribute_objc_ivar_unused)
|
|
|
|
#define UNUSED_IVAR __attribute__((unused))
|
|
|
|
#else
|
|
|
|
#error __attribute__((unused)) not supported on ivars
|
|
|
|
#endif
|
|
|
|
|
2010-02-25 11:26:51 +08:00
|
|
|
@interface TestUnusedIvar {
|
2010-03-06 06:43:32 +08:00
|
|
|
id y __attribute__((unused)); // no-warning
|
|
|
|
id x UNUSED_IVAR; // no-warning
|
2010-02-25 11:26:51 +08:00
|
|
|
}
|
|
|
|
@end
|
2010-03-06 06:43:32 +08:00
|
|
|
|
2012-08-04 09:24:33 +08:00
|
|
|
// rdar://10777111
|
|
|
|
static NSString *x = @"hi"; // expected-warning {{unused variable 'x'}}
|
2012-09-07 02:38:58 +08:00
|
|
|
|
|
|
|
// rdar://12233989
|
|
|
|
@interface TestTransitiveUnused
|
|
|
|
- (void) a __attribute__((unused));
|
|
|
|
- (void) b __attribute__((unused));
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface TestTransitiveUnused(CAT)
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TestTransitiveUnused(CAT)
|
|
|
|
- (void) b {}
|
|
|
|
- (void) a { [self b]; }
|
|
|
|
@end
|
2014-01-10 04:19:45 +08:00
|
|
|
|
|
|
|
// Test that objc_precise_lifetime suppresses
|
|
|
|
// unused variable warnings.
|
|
|
|
extern void rdar15596883_foo(void);
|
|
|
|
void rdar15596883(id x) {
|
|
|
|
__attribute__((objc_precise_lifetime)) id y = x; // no-warning
|
|
|
|
rdar15596883_foo();
|
|
|
|
}
|
|
|
|
|
2014-07-19 06:59:10 +08:00
|
|
|
@interface PropertyObject : NSObject
|
|
|
|
@property int length;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@protocol P
|
|
|
|
@property int property;
|
|
|
|
@end
|
|
|
|
|
|
|
|
void test3(PropertyObject *o)
|
|
|
|
{
|
|
|
|
[o length]; // expected-warning {{property access result unused - getters should not be used for side effects}}
|
|
|
|
(void)[o length];
|
|
|
|
}
|
|
|
|
|
|
|
|
void test4(id o)
|
|
|
|
{
|
|
|
|
[o length]; // No warning.
|
|
|
|
}
|
|
|
|
|
|
|
|
void test5(id <P> p)
|
|
|
|
{
|
|
|
|
[p property]; // expected-warning {{property access result unused - getters should not be used for side effects}}
|
|
|
|
}
|