Lines Matching defs:relativeEnd

1 // RUN: %check_clang_tidy %s bugprone-assert-side-effect %t -- -config="{CheckOptions: [{key: bugpr…
2
3 //===--- assert definition block ------------------------------------------===//
4 int abort() { return 0; }
5
6 #ifdef NDEBUG
7 #define assert(x) 1
8 #else
9 #define assert(x) \
10 if (!(x)) \
11 (void)abort()
12 #endif
13
14 void print(...);
15 #define assert2(e) (__builtin_expect(!(e), 0) ? \
16 print (#e, __FILE__, __LINE__) : (void)0)
17
18 #ifdef NDEBUG
19 #define my_assert(x) 1
20 #else
21 #define my_assert(x) \
22 ((void)((x) ? 1 : abort()))
23 #endif
24
25 #ifdef NDEBUG
26 #define not_my_assert(x) 1
27 #else
28 #define not_my_assert(x) \
29 if (!(x)) \
30 (void)abort()
31 #endif
32 in Part_SetInfo()
33 #define real_assert(x) ((void)((x) ? 1 : abort())) in Part_SetInfo()
34 #define wrap1(x) real_assert(x) in Part_SetInfo()
35 #define wrap2(x) wrap1(x) in Part_SetInfo()
36 #define convoluted_assert(x) wrap2(x) in Part_SetInfo()
37 in Part_SetInfo()
38 #define msvc_assert(expression) (void)( \ in Part_SetInfo()
39 (!!(expression)) || \ in Part_SetInfo()
40 (abort(), 0) \ in Part_SetInfo()
41 ) in Part_SetInfo()
42 in Part_SetInfo()
43 in Part_SetInfo()
44 //===----------------------------------------------------------------------===// in Part_SetInfo()
45 in Part_SetInfo()
46 class MyClass { in Part_SetInfo()
47 public: in Part_SetInfo()
48 bool badFunc(int a, int b) { return a * b > 0; } in Part_SetInfo()
49 bool goodFunc(int a, int b) const { return a * b > 0; } in Part_SetInfo()
50 in Part_SetInfo()
51 MyClass &operator=(const MyClass &rhs) { return *this; } in Part_SetInfo()
52 in Part_SetInfo()
53 int operator-() { return 1; } in Part_SetInfo()
54 in Part_SetInfo()
55 operator bool() const { return true; } in Part_SetInfo()
56 in Part_SetInfo()
57 void operator delete(void *p) {} in Part_SetInfo()
58 }; in Part_SetInfo()
59
60 bool freeFunction() {
61 return true;
62 }
63
64 int main() {
65
66 int X = 0;
67 bool B = false;
68 assert(X == 1);
69
70 assert(X = 1);
71 …// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect [bugprone-assert-side-… in Part_SetPhrase()
72 my_assert(X = 1); in Part_SetPhrase()
73 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found my_assert() with side effect
74 convoluted_assert(X = 1);
75 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found convoluted_assert() with side effect
76 not_my_assert(X = 1);
77 in executeImpl()
78 assert(++X); in executeImpl()
79 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
80 assert(!B);
81
82 assert(B || true);
83
84 assert(freeFunction()); in undoImpl()
85 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
86
87 MyClass mc;
88 assert(mc.badFunc(0, 1));
89 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
90 assert(mc.goodFunc(0, 1));
91
92 MyClass mc2;
93 assert(mc2 = mc);
94 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect in Part_Move()
95 in Part_Move()
96 assert(-mc > 0); in Part_Move()
97
98 MyClass *mcp;
99 assert(mcp = new MyClass);
100 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
101
102 assert((delete mcp, false));
103 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
104
105 assert((throw 1, false));
106 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
107
108 assert2(1 == 2 - 1);
109
110 msvc_assert(mc2 = mc);
111 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found msvc_assert() with side effect
112
113 return 0;
114 }