• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -verify -Wused-but-marked-unused -Wno-objc-protocol-method-implementation -Wunused -Wunused-parameter -fsyntax-only -Wno-objc-root-class %s
2
3int 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
13int test1(void) {
14  [Greeter hello];
15  return 0;
16}
17
18@interface NSObject @end
19@interface NSString : NSObject
20- (int)length;
21@end
22
23void 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: // 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}}
35
36(int)y:  // expected-warning {{unused}}  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; }
40@end
41
42//===------------------------------------------------------------------------===
43// The next test shows how clang accepted attribute((unused)) on ObjC
44// instance variables, which GCC does not.
45//===------------------------------------------------------------------------===
46
47#if __has_feature(attribute_objc_ivar_unused)
48#define UNUSED_IVAR __attribute__((unused))
49#else
50#error __attribute__((unused)) not supported on ivars
51#endif
52
53@interface TestUnusedIvar {
54  id y __attribute__((unused)); // no-warning
55  id x UNUSED_IVAR; // no-warning
56}
57@end
58
59// rdar://10777111
60static NSString *x = @"hi"; // expected-warning {{unused variable 'x'}}
61
62// rdar://12233989
63@interface TestTransitiveUnused
64- (void) a __attribute__((unused));
65- (void) b __attribute__((unused));
66@end
67
68@interface TestTransitiveUnused(CAT)
69@end
70
71@implementation TestTransitiveUnused(CAT)
72- (void) b {}
73- (void) a { [self b]; }
74@end
75