blob: 1ecf32295eaed7f7213f218d4a03360e06b4f2b8 [file] [log] [blame]
Ted Kremenekb4c0c2d2010-04-08 21:10:56 +00001// RUN: %clang_cc1 %s -verify -Wunused -Wunused-parameter -fsyntax-only
Daniel Dunbar23afaad2009-11-17 08:57:36 +00002
3int printf(const char *, ...);
Chris Lattnera9c01022007-09-26 22:06:30 +00004
5@interface Greeter
6+ (void) hello;
7@end
8
9@implementation Greeter
Ted Kremenek2ec93a82010-02-25 03:26:51 +000010+ (void) hello { printf("Hello, World!\n"); }
Chris Lattnera9c01022007-09-26 22:06:30 +000011@end
12
Chris Lattnerbab8a8e2009-08-11 20:08:52 +000013int test1(void) {
14 [Greeter hello];
15 return 0;
16}
17
Chris Lattnerab0e8872009-08-11 20:08:03 +000018@interface NSObject @end
19@interface NSString : NSObject
20- (int)length;
21@end
22
Chris Lattnerbab8a8e2009-08-11 20:08:52 +000023void test2() {
Chris Lattnerbc0b9152010-04-26 21:44:01 +000024 @"pointless example call for test purposes".length; // expected-warning {{property access result unused - getters should not be used for side effects}}
Chris Lattnerab0e8872009-08-11 20:08:03 +000025}
26
Chris Lattnerbab8a8e2009-08-11 20:08:52 +000027@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
Ted Kremenek2ec93a82010-02-25 03:26:51 +000036
37//===------------------------------------------------------------------------===
38// The next test shows how clang accepted attribute((unused)) on ObjC
39// instance variables, which GCC does not.
40//===------------------------------------------------------------------------===
41
Ted Kremenek444b0352010-03-05 22:43:32 +000042#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
Ted Kremenek2ec93a82010-02-25 03:26:51 +000048@interface TestUnusedIvar {
Ted Kremenek444b0352010-03-05 22:43:32 +000049 id y __attribute__((unused)); // no-warning
50 id x UNUSED_IVAR; // no-warning
Ted Kremenek2ec93a82010-02-25 03:26:51 +000051}
52@end
Ted Kremenek444b0352010-03-05 22:43:32 +000053