brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · def52ce Raw
128 lines · plain
1// RUN: %clang_cc1 -verify -Wused-but-marked-unused -Wno-objc-protocol-method-implementation -Wunused -Wunused-parameter -fsyntax-only -Wno-objc-root-class %s2 3int printf(const char *, ...);4 5@interface Greeter6+ (void) hello;7@end8 9@implementation Greeter10+ (void) hello { printf("Hello, World!\n"); }11@end12 13int test1(void) {14  [Greeter hello];15  return 0;16}17 18@interface NSObject @end19@interface NSString : NSObject 20- (int)length;21@end22 23void test2(void) {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 foo28- (int)meth: (int)x : (int)y : (int)z ;29@end30 31@implementation foo32- (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 {{'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@end41 42//===------------------------------------------------------------------------===43// The next test shows how clang accepted attribute((unused)) on ObjC44// instance variables, which GCC does not.45//===------------------------------------------------------------------------===46 47#if __has_feature(attribute_objc_ivar_unused)48#define UNUSED_IVAR __attribute__((unused))49#else50#error __attribute__((unused)) not supported on ivars51#endif52 53@interface TestUnusedIvar {54  id y __attribute__((unused)); // no-warning55  id x UNUSED_IVAR; // no-warning56}57@end58 59static NSString *x = @"hi"; // expected-warning {{unused variable 'x'}}60 61@interface TestTransitiveUnused62- (void) a __attribute__((unused));63- (void) b __attribute__((unused));64@end65 66@interface TestTransitiveUnused(CAT)67@end68 69@implementation TestTransitiveUnused(CAT)70- (void) b {}71- (void) a { [self b]; }72@end73 74// Test that objc_precise_lifetime suppresses75// unused variable warnings.76extern void rdar15596883_foo(void);77void rdar15596883(id x) {78  __attribute__((objc_precise_lifetime)) id y = x; // no-warning79  rdar15596883_foo();80}81 82@interface PropertyObject : NSObject 83@property int length;84@end85 86@protocol P87@property int property;88@end89 90void test3(PropertyObject *o)91{92  [o length]; // No warning. property name used in direct method call.93}94 95void test4(id o)96{97  [o length]; // No warning.98}99 100void test5(id <P> p)101{102    [p property]; // No warning. property name used in direct method call.103}104 105@interface Model106@property (nonatomic, retain, setter=setOrCreateGroup:, getter=getOrCreateGroup) id group;107@end108 109@implementation Model {110    id _group;111}112- (void)method {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)];118    119}120- (id)getOrCreateGroup {121    if (!_group) {122        _group = @"group";123    }124    return _group;125}126@end127 128