freebsd-dev/test/SemaObjC/unused.m

54 lines
1.2 KiB
Mathematica
Raw Normal View History

2010-05-04 16:12:48 +00:00
// RUN: %clang_cc1 %s -verify -Wunused -Wunused-parameter -fsyntax-only
2009-11-18 14:59:57 +00:00
int printf(const char *, ...);
2009-06-02 17:58:47 +00:00
@interface Greeter
+ (void) hello;
@end
@implementation Greeter
2010-03-03 17:28:16 +00:00
+ (void) hello { printf("Hello, World!\n"); }
2009-06-02 17:58:47 +00:00
@end
2009-10-14 18:03:49 +00:00
int test1(void) {
[Greeter hello];
return 0;
}
@interface NSObject @end
@interface NSString : NSObject
- (int)length;
@end
void test2() {
2010-05-04 16:12:48 +00:00
@"pointless example call for test purposes".length; // expected-warning {{property access result unused - getters should not be used for side effects}}
2009-06-02 17:58:47 +00:00
}
2009-10-14 18:03:49 +00:00
@interface foo
- (int)meth: (int)x: (int)y: (int)z ;
@end
@implementation foo
- (int) meth: (int)x:
(int)y: // expected-warning{{unused}}
(int) __attribute__((unused))z { return x; }
@end
2010-03-03 17:28:16 +00:00
//===------------------------------------------------------------------------===
// The next test shows how clang accepted attribute((unused)) on ObjC
// instance variables, which GCC does not.
//===------------------------------------------------------------------------===
2010-03-06 09:23:02 +00:00
#if __has_feature(attribute_objc_ivar_unused)
#define UNUSED_IVAR __attribute__((unused))
#else
#error __attribute__((unused)) not supported on ivars
#endif
2010-03-03 17:28:16 +00:00
@interface TestUnusedIvar {
2010-03-06 09:23:02 +00:00
id y __attribute__((unused)); // no-warning
id x UNUSED_IVAR; // no-warning
2010-03-03 17:28:16 +00:00
}
@end
2010-03-06 09:23:02 +00:00