|
| 1 | +// RUN: %check_clang_tidy -std=c++98,c++11,c++14,c++17,c++20 -check-suffixes=,CXX %s readability-use-concise-preprocessor-directives %t |
| 2 | +// RUN: %check_clang_tidy -std=c++23-or-later -check-suffixes=,23,CXX,CXX23 %s readability-use-concise-preprocessor-directives %t |
| 3 | + |
| 4 | +// RUN: %check_clang_tidy -std=c99,c11,c17 %s readability-use-concise-preprocessor-directives %t -- -- -x c |
| 5 | +// RUN: %check_clang_tidy -std=c23-or-later -check-suffixes=,23 %s readability-use-concise-preprocessor-directives %t -- -- -x c |
| 6 | + |
| 7 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives] |
| 8 | +// CHECK-FIXES: #ifdef FOO |
| 9 | +#if defined(FOO) |
| 10 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives] |
| 11 | +// CHECK-FIXES-23: #elifdef BAR |
| 12 | +#elif defined(BAR) |
| 13 | +#endif |
| 14 | + |
| 15 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives] |
| 16 | +// CHECK-FIXES: #ifdef FOO |
| 17 | +#if defined FOO |
| 18 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives] |
| 19 | +// CHECK-FIXES-23: #elifdef BAR |
| 20 | +#elif defined BAR |
| 21 | +#endif |
| 22 | + |
| 23 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives] |
| 24 | +// CHECK-FIXES: #ifdef FOO |
| 25 | +#if (defined(FOO)) |
| 26 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives] |
| 27 | +// CHECK-FIXES-23: # elifdef BAR |
| 28 | +# elif (defined(BAR)) |
| 29 | +#endif |
| 30 | + |
| 31 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives] |
| 32 | +// CHECK-FIXES: #ifdef FOO |
| 33 | +#if (defined FOO) |
| 34 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives] |
| 35 | +// CHECK-FIXES-23: # elifdef BAR |
| 36 | +# elif (defined BAR) |
| 37 | +#endif |
| 38 | + |
| 39 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 40 | +// CHECK-FIXES: #ifndef FOO |
| 41 | +#if !defined(FOO) |
| 42 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives] |
| 43 | +// CHECK-FIXES-23: #elifndef BAR |
| 44 | +#elif !defined(BAR) |
| 45 | +#endif |
| 46 | + |
| 47 | +#ifdef __cplusplus |
| 48 | +// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 49 | +// CHECK-FIXES-CXX: #ifndef FOO |
| 50 | +#if not defined(FOO) |
| 51 | +// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives] |
| 52 | +// CHECK-FIXES-CXX23: #elifndef BAR |
| 53 | +#elif not defined(BAR) |
| 54 | +#endif |
| 55 | +#endif // __cplusplus |
| 56 | + |
| 57 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 58 | +// CHECK-FIXES: #ifndef FOO |
| 59 | +#if !defined FOO |
| 60 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives] |
| 61 | +// CHECK-FIXES-23: #elifndef BAR |
| 62 | +#elif !defined BAR |
| 63 | +#endif |
| 64 | + |
| 65 | +#ifdef __cplusplus |
| 66 | +// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 67 | +// CHECK-FIXES-CXX: #ifndef FOO |
| 68 | +#if not defined FOO |
| 69 | +// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives] |
| 70 | +// CHECK-FIXES-CXX23: #elifndef BAR |
| 71 | +#elif not defined BAR |
| 72 | +#endif |
| 73 | +#endif // __cplusplus |
| 74 | + |
| 75 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 76 | +// CHECK-FIXES: #ifndef FOO |
| 77 | +#if (!defined(FOO)) |
| 78 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives] |
| 79 | +// CHECK-FIXES-23: #elifndef BAR |
| 80 | +#elif (!defined(BAR)) |
| 81 | +#endif |
| 82 | + |
| 83 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 84 | +// CHECK-FIXES: #ifndef FOO |
| 85 | +#if (!defined FOO) |
| 86 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives] |
| 87 | +// CHECK-FIXES-23: #elifndef BAR |
| 88 | +#elif (!defined BAR) |
| 89 | +#endif |
| 90 | + |
| 91 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 92 | +// CHECK-FIXES: #ifndef FOO |
| 93 | +#if !(defined(FOO)) |
| 94 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives] |
| 95 | +// CHECK-FIXES-23: #elifndef BAR |
| 96 | +#elif !(defined(BAR)) |
| 97 | +#endif |
| 98 | + |
| 99 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 100 | +// CHECK-FIXES: #ifndef FOO |
| 101 | +#if !(defined FOO) |
| 102 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives] |
| 103 | +// CHECK-FIXES-23: #elifndef BAR |
| 104 | +#elif !(defined BAR) |
| 105 | +#endif |
| 106 | + |
| 107 | +// These cases with many parentheses and negations are unrealistic, but |
| 108 | +// handling them doesn't really add any complexity to the implementation. |
| 109 | +// Test them for good measure. |
| 110 | + |
| 111 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 112 | +// CHECK-FIXES: #ifndef FOO |
| 113 | +#if !((!!(defined(FOO)))) |
| 114 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives] |
| 115 | +// CHECK-FIXES-23: #elifdef BAR |
| 116 | +#elif ((!(!(defined(BAR))))) |
| 117 | +#endif |
| 118 | + |
| 119 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 120 | +// CHECK-FIXES: #ifndef FOO |
| 121 | +#if !((!!(defined FOO))) |
| 122 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives] |
| 123 | +// CHECK-FIXES-23: #elifdef BAR |
| 124 | +#elif ((!(!(defined BAR)))) |
| 125 | +#endif |
| 126 | + |
| 127 | +// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives] |
| 128 | +// CHECK-FIXES: #ifndef FOO |
| 129 | +#if !( (!! ( defined FOO )) ) |
| 130 | +// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives] |
| 131 | +// CHECK-FIXES-23: #elifdef BAR |
| 132 | +#elif ( ( !(!( defined BAR) ) )) |
| 133 | +#endif |
| 134 | + |
| 135 | +#if FOO |
| 136 | +#elif BAR |
| 137 | +#endif |
| 138 | + |
| 139 | +#if defined(FOO) && defined(BAR) |
| 140 | +#elif defined(FOO) && defined(BAR) |
| 141 | +#endif |
| 142 | + |
| 143 | +#if defined FOO && BAR |
| 144 | +#endif |
0 commit comments