54 lines · plain
1// RUN: %check_clang_tidy %s bugprone-assert-side-effect %t2 3int abort(void);4 5@interface NSObject6@end7 8@interface NSString9@end10 11@interface NSAssertionHandler12+ (NSAssertionHandler *)currentHandler;13- handleFailureInMethod:(SEL)cmd object:(NSObject *)obj desc:(NSString *)desc;14- handleFailureInFunction:(NSString *)desc;15@end16 17#ifndef NDEBUG18#define NSAssert(condition, description, ...) \19 do { \20 if (__builtin_expect(!(condition), 0)) { \21 [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd \22 object:self \23 desc:(description)]; \24 } \25 } while (0);26#define NSCAssert(condition, description, ...) \27 do { \28 if (__builtin_expect(!(condition), 0)) { \29 [[NSAssertionHandler currentHandler] handleFailureInFunction:(description)]; \30 } \31 } while (0);32#else33#define NSAssert(condition, description, ...) do {} while (0)34#define NSCAssert(condition, description, ...) do {} while (0)35#endif36 37@interface I : NSObject38- (void)foo;39@end40 41@implementation I42- (void)foo {43 int x = 0;44 NSAssert((++x) == 1, @"Ugh.");45 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in NSAssert() condition discarded in release builds [bugprone-assert-side-effect]46}47@end48 49void foo(void) {50 int x = 0;51 NSCAssert((++x) == 1, @"Ugh.");52 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in NSCAssert() condition discarded in release builds [bugprone-assert-side-effect]53}54