1 | // RUN: %check_clang_tidy %s bugprone-assert-side-effect %t |
2 | |
3 | int abort(void); |
4 | |
5 | @interface NSObject |
6 | @end |
7 | |
8 | @interface NSString |
9 | @end |
10 | |
11 | @interface NSAssertionHandler |
12 | + (NSAssertionHandler *)currentHandler; |
13 | - handleFailureInMethod:(SEL)cmd object:(NSObject *)obj desc:(NSString *)desc; |
14 | - handleFailureInFunction:(NSString *)desc; |
15 | @end |
16 | |
17 | #ifndef NDEBUG |
18 | #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 | #else |
33 | #define NSAssert(condition, description, ...) do {} while (0) |
34 | #define NSCAssert(condition, description, ...) do {} while (0) |
35 | #endif |
36 | |
37 | @interface I : NSObject |
38 | - (void)foo; |
39 | @end |
40 | |
41 | @implementation I |
42 | - (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 | @end |
48 | |
49 | void 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 | |