1// RUN: %check_clang_tidy %s android-comparison-in-temp-failure-retry %t -- -config="{CheckOptions: {android-comparison-in-temp-failure-retry.RetryMacros: 'MY_TEMP_FAILURE_RETRY,MY_OTHER_TEMP_FAILURE_RETRY'}}"
2
3#define MY_TEMP_FAILURE_RETRY(x) \
4 ({ \
5 typeof(x) __z; \
6 do \
7 __z = (x); \
8 while (__z == -1); \
9 __z; \
10 })
11
12#define MY_OTHER_TEMP_FAILURE_RETRY(x) \
13 ({ \
14 typeof(x) __z; \
15 do \
16 __z = (x); \
17 while (__z == -1); \
18 __z; \
19 })
20
21int foo(void);
22int bar(int a);
23
24void with_custom_macro(void) {
25 MY_TEMP_FAILURE_RETRY(foo());
26 MY_TEMP_FAILURE_RETRY(foo() == 1);
27 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: top-level comparison in MY_TEMP_FAILURE_RETRY
28 MY_TEMP_FAILURE_RETRY((foo()));
29 MY_TEMP_FAILURE_RETRY((int)(foo() == 1));
30 // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: top-level comparison in MY_TEMP_FAILURE_RETRY
31 MY_TEMP_FAILURE_RETRY((bar(foo() == 1)));
32 MY_TEMP_FAILURE_RETRY((int)((bar(foo() == 1)) == 1));
33 // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: top-level comparison in MY_TEMP_FAILURE_RETRY
34}
35
36void with_other_custom_macro(void) {
37 MY_OTHER_TEMP_FAILURE_RETRY(foo());
38 MY_OTHER_TEMP_FAILURE_RETRY(foo() == 1);
39 // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: top-level comparison in MY_OTHER_TEMP_FAILURE_RETRY
40 MY_OTHER_TEMP_FAILURE_RETRY((foo()));
41 MY_OTHER_TEMP_FAILURE_RETRY((int)(foo() == 1));
42 // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: top-level comparison in MY_OTHER_TEMP_FAILURE_RETRY
43 MY_OTHER_TEMP_FAILURE_RETRY((bar(foo() == 1)));
44 MY_OTHER_TEMP_FAILURE_RETRY((int)((bar(foo() == 1)) == 1));
45 // CHECK-MESSAGES: :[[@LINE-1]]:55: warning: top-level comparison in MY_OTHER_TEMP_FAILURE_RETRY
46}
47

source code of clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c