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