Skip to content

Commit a2d0a59

Browse files
committed
Address feedback
1 parent 212e5e4 commit a2d0a59

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

clang-tools-extra/clang-tidy/readability/UseConcisePreprocessorDirectivesCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class IfPreprocessorCallbacks final : public PPCallbacks {
8787
if (ParensNestingDepth != 0)
8888
return;
8989

90-
Check.diag(DirectiveLoc,
91-
"preprocessor condition can be written more concisely using #%0")
90+
Check.diag(
91+
DirectiveLoc,
92+
"preprocessor condition can be written more concisely using '#%0'")
9293
<< FixItHint::CreateReplacement(DirectiveLoc, Replacements[Inverted])
9394
<< FixItHint::CreateReplacement(ConditionRange, Macro)
9495
<< Replacements[Inverted];

clang-tools-extra/clang-tidy/readability/UseConcisePreprocessorDirectivesCheck.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@
1313

1414
namespace clang::tidy::readability {
1515

16-
/// Shortens `#if` preprocessor conditions:
17-
///
18-
/// #if defined(MEOW) -> #ifdef MEOW
19-
/// #if !defined(MEOW) -> #ifndef MEOW
20-
///
21-
/// And, since C23 and C++23, shortens `#elif` conditions too:
22-
///
23-
/// #elif defined(MEOW) -> #elifdef MEOW
24-
/// #elif !defined(MEOW) -> #elifndef MEOW
16+
/// Finds uses of ``#if`` that can be simplified to ``#ifdef`` or ``#ifndef``
17+
/// and, since C23 and C++23, uses of ``#elif`` that can be simplified to
18+
/// ``#elifdef`` or ``#elifndef``.
2519
///
2620
/// User-facing documentation:
2721
/// https://clang.llvm.org/extra/clang-tidy/checks/readability/use-concise-preprocessor-directives.html
Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,105 @@
1-
// RUN: %check_clang_tidy -std=c++98 -check-suffixes=,CXX %s readability-use-concise-preprocessor-directives %t
2-
// RUN: %check_clang_tidy -std=c++11 -check-suffixes=,CXX %s readability-use-concise-preprocessor-directives %t
3-
// RUN: %check_clang_tidy -std=c++14 -check-suffixes=,CXX %s readability-use-concise-preprocessor-directives %t
4-
// RUN: %check_clang_tidy -std=c++17 -check-suffixes=,CXX %s readability-use-concise-preprocessor-directives %t
5-
// RUN: %check_clang_tidy -std=c++20 -check-suffixes=,CXX %s readability-use-concise-preprocessor-directives %t
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
62
// RUN: %check_clang_tidy -std=c++23-or-later -check-suffixes=,23,CXX,CXX23 %s readability-use-concise-preprocessor-directives %t
73

8-
// RUN: %check_clang_tidy -std=c99 %s readability-use-concise-preprocessor-directives %t -- -- -x c
9-
// RUN: %check_clang_tidy -std=c11 %s readability-use-concise-preprocessor-directives %t -- -- -x c
4+
// RUN: %check_clang_tidy -std=c99,c17,c11 %s readability-use-concise-preprocessor-directives %t -- -- -x c
105
// RUN: %check_clang_tidy -std=c23-or-later -check-suffixes=,23 %s readability-use-concise-preprocessor-directives %t -- -- -x c
116

12-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifdef [readability-use-concise-preprocessor-directives]
7+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
138
// CHECK-FIXES: #ifdef FOO
149
#if defined(FOO)
15-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifdef [readability-use-concise-preprocessor-directives]
10+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
1611
// CHECK-FIXES-23: #elifdef BAR
1712
#elif defined(BAR)
1813
#endif
1914

20-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifdef [readability-use-concise-preprocessor-directives]
15+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
2116
// CHECK-FIXES: #ifdef FOO
2217
#if defined FOO
23-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifdef [readability-use-concise-preprocessor-directives]
18+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
2419
// CHECK-FIXES-23: #elifdef BAR
2520
#elif defined BAR
2621
#endif
2722

28-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifdef [readability-use-concise-preprocessor-directives]
23+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
2924
// CHECK-FIXES: #ifdef FOO
3025
#if (defined(FOO))
31-
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using #elifdef [readability-use-concise-preprocessor-directives]
26+
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
3227
// CHECK-FIXES-23: # elifdef BAR
3328
# elif (defined(BAR))
3429
#endif
3530

36-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifdef [readability-use-concise-preprocessor-directives]
31+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
3732
// CHECK-FIXES: #ifdef FOO
3833
#if (defined FOO)
39-
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using #elifdef [readability-use-concise-preprocessor-directives]
34+
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
4035
// CHECK-FIXES-23: # elifdef BAR
4136
# elif (defined BAR)
4237
#endif
4338

44-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
39+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
4540
// CHECK-FIXES: #ifndef FOO
4641
#if !defined(FOO)
47-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [readability-use-concise-preprocessor-directives]
42+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives]
4843
// CHECK-FIXES-23: #elifndef BAR
4944
#elif !defined(BAR)
5045
#endif
5146

5247
#ifdef __cplusplus
53-
// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
48+
// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
5449
// CHECK-FIXES-CXX: #ifndef FOO
5550
#if not defined(FOO)
56-
// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [readability-use-concise-preprocessor-directives]
51+
// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives]
5752
// CHECK-FIXES-CXX23: #elifndef BAR
5853
#elif not defined(BAR)
5954
#endif
6055
#endif // __cplusplus
6156

62-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
57+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
6358
// CHECK-FIXES: #ifndef FOO
6459
#if !defined FOO
65-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [readability-use-concise-preprocessor-directives]
60+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives]
6661
// CHECK-FIXES-23: #elifndef BAR
6762
#elif !defined BAR
6863
#endif
6964

7065
#ifdef __cplusplus
71-
// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
66+
// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
7267
// CHECK-FIXES-CXX: #ifndef FOO
7368
#if not defined FOO
74-
// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [readability-use-concise-preprocessor-directives]
69+
// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives]
7570
// CHECK-FIXES-CXX23: #elifndef BAR
7671
#elif not defined BAR
7772
#endif
7873
#endif // __cplusplus
7974

80-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
75+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
8176
// CHECK-FIXES: #ifndef FOO
8277
#if (!defined(FOO))
83-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [readability-use-concise-preprocessor-directives]
78+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives]
8479
// CHECK-FIXES-23: #elifndef BAR
8580
#elif (!defined(BAR))
8681
#endif
8782

88-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
83+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
8984
// CHECK-FIXES: #ifndef FOO
9085
#if (!defined FOO)
91-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [readability-use-concise-preprocessor-directives]
86+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives]
9287
// CHECK-FIXES-23: #elifndef BAR
9388
#elif (!defined BAR)
9489
#endif
9590

96-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
91+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
9792
// CHECK-FIXES: #ifndef FOO
9893
#if !(defined(FOO))
99-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [readability-use-concise-preprocessor-directives]
94+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives]
10095
// CHECK-FIXES-23: #elifndef BAR
10196
#elif !(defined(BAR))
10297
#endif
10398

104-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
99+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
105100
// CHECK-FIXES: #ifndef FOO
106101
#if !(defined FOO)
107-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [readability-use-concise-preprocessor-directives]
102+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifndef' [readability-use-concise-preprocessor-directives]
108103
// CHECK-FIXES-23: #elifndef BAR
109104
#elif !(defined BAR)
110105
#endif
@@ -113,26 +108,37 @@
113108
// handling them doesn't really add any complexity to the implementation.
114109
// Test them for good measure.
115110

116-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
111+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
117112
// CHECK-FIXES: #ifndef FOO
118113
#if !((!!(defined(FOO))))
119-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifdef [readability-use-concise-preprocessor-directives]
114+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
120115
// CHECK-FIXES-23: #elifdef BAR
121116
#elif ((!(!(defined(BAR)))))
122117
#endif
123118

124-
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [readability-use-concise-preprocessor-directives]
119+
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifndef' [readability-use-concise-preprocessor-directives]
125120
// CHECK-FIXES: #ifndef FOO
126121
#if !((!!(defined FOO)))
127-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifdef [readability-use-concise-preprocessor-directives]
122+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
128123
// CHECK-FIXES-23: #elifdef BAR
129124
#elif ((!(!(defined BAR))))
130125
#endif
131126

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+
132135
#if FOO
133136
#elif BAR
134137
#endif
135138

136139
#if defined(FOO) && defined(BAR)
137140
#elif defined(FOO) && defined(BAR)
138141
#endif
142+
143+
#if defined FOO && BAR
144+
#endif

0 commit comments

Comments
 (0)