Skip to content

Commit ce0e935

Browse files
committed
Update message, add test
1 parent 3ef8a8d commit ce0e935

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ class IfPreprocessorCallbacks final : public PPCallbacks {
8888
return;
8989

9090
Check.diag(DirectiveLoc,
91-
"preprocessor condition can be written more concisely")
91+
"preprocessor condition can be written more concisely using #%0")
9292
<< FixItHint::CreateReplacement(DirectiveLoc, Replacements[Inverted])
93-
<< FixItHint::CreateReplacement(ConditionRange, Macro);
93+
<< FixItHint::CreateReplacement(ConditionRange, Macro)
94+
<< Replacements[Inverted];
9495
}
9596

9697
ClangTidyCheck &Check;

clang-tools-extra/test/clang-tidy/checkers/modernize/use-concise-preprocessor-directives.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,102 +9,102 @@
99
// RUN: %check_clang_tidy -std=c11 -check-suffix=ALL %s modernize-use-concise-preprocessor-directives %t -- -- -x c
1010
// RUN: %check_clang_tidy -std=c23-or-later -check-suffix=ALL,23 %s modernize-use-concise-preprocessor-directives %t -- -- -x c
1111

12-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
12+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifdef [modernize-use-concise-preprocessor-directives]
1313
// CHECK-FIXES-ALL: #ifdef FOO
1414
#if defined(FOO)
15-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
15+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifdef [modernize-use-concise-preprocessor-directives]
1616
// CHECK-FIXES-23: #elifdef BAR
1717
#elif defined(BAR)
1818
#endif
1919

20-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
20+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifdef [modernize-use-concise-preprocessor-directives]
2121
// CHECK-FIXES-ALL: #ifdef FOO
2222
#if defined FOO
23-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
23+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifdef [modernize-use-concise-preprocessor-directives]
2424
// CHECK-FIXES-23: #elifdef BAR
2525
#elif defined BAR
2626
#endif
2727

28-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
28+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifdef [modernize-use-concise-preprocessor-directives]
2929
// CHECK-FIXES-ALL: #ifdef FOO
3030
#if (defined(FOO))
31-
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
31+
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using #elifdef [modernize-use-concise-preprocessor-directives]
3232
// CHECK-FIXES-23: # elifdef BAR
3333
# elif (defined(BAR))
3434
#endif
3535

36-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
36+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifdef [modernize-use-concise-preprocessor-directives]
3737
// CHECK-FIXES-ALL: #ifdef FOO
3838
#if (defined FOO)
39-
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
39+
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using #elifdef [modernize-use-concise-preprocessor-directives]
4040
// CHECK-FIXES-23: # elifdef BAR
4141
# elif (defined BAR)
4242
#endif
4343

44-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
44+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
4545
// CHECK-FIXES-ALL: #ifndef FOO
4646
#if !defined(FOO)
47-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
47+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [modernize-use-concise-preprocessor-directives]
4848
// CHECK-FIXES-23: #elifndef BAR
4949
#elif !defined(BAR)
5050
#endif
5151

5252
#ifdef __cplusplus
53-
// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
53+
// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
5454
// CHECK-FIXES-CXX: #ifndef FOO
5555
#if not defined(FOO)
56-
// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
56+
// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [modernize-use-concise-preprocessor-directives]
5757
// CHECK-FIXES-CXX23: #elifndef BAR
5858
#elif not defined(BAR)
5959
#endif
6060
#endif // __cplusplus
6161

62-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
62+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
6363
// CHECK-FIXES-ALL: #ifndef FOO
6464
#if !defined FOO
65-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
65+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [modernize-use-concise-preprocessor-directives]
6666
// CHECK-FIXES-23: #elifndef BAR
6767
#elif !defined BAR
6868
#endif
6969

7070
#ifdef __cplusplus
71-
// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
71+
// CHECK-MESSAGES-CXX: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
7272
// CHECK-FIXES-CXX: #ifndef FOO
7373
#if not defined FOO
74-
// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
74+
// CHECK-MESSAGES-CXX23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [modernize-use-concise-preprocessor-directives]
7575
// CHECK-FIXES-CXX23: #elifndef BAR
7676
#elif not defined BAR
7777
#endif
7878
#endif // __cplusplus
7979

80-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
80+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
8181
// CHECK-FIXES-ALL: #ifndef FOO
8282
#if (!defined(FOO))
83-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
83+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [modernize-use-concise-preprocessor-directives]
8484
// CHECK-FIXES-23: #elifndef BAR
8585
#elif (!defined(BAR))
8686
#endif
8787

88-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
88+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
8989
// CHECK-FIXES-ALL: #ifndef FOO
9090
#if (!defined FOO)
91-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
91+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [modernize-use-concise-preprocessor-directives]
9292
// CHECK-FIXES-23: #elifndef BAR
9393
#elif (!defined BAR)
9494
#endif
9595

96-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
96+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
9797
// CHECK-FIXES-ALL: #ifndef FOO
9898
#if !(defined(FOO))
99-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
99+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [modernize-use-concise-preprocessor-directives]
100100
// CHECK-FIXES-23: #elifndef BAR
101101
#elif !(defined(BAR))
102102
#endif
103103

104-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
104+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
105105
// CHECK-FIXES-ALL: #ifndef FOO
106106
#if !(defined FOO)
107-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
107+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifndef [modernize-use-concise-preprocessor-directives]
108108
// CHECK-FIXES-23: #elifndef BAR
109109
#elif !(defined BAR)
110110
#endif
@@ -113,22 +113,26 @@
113113
// handling them doesn't really add any complexity to the implementation.
114114
// Test them for good measure.
115115

116-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
116+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
117117
// CHECK-FIXES-ALL: #ifndef FOO
118118
#if !((!!(defined(FOO))))
119-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
119+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifdef [modernize-use-concise-preprocessor-directives]
120120
// CHECK-FIXES-23: #elifdef BAR
121121
#elif ((!(!(defined(BAR)))))
122122
#endif
123123

124-
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
124+
// CHECK-MESSAGES-ALL: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #ifndef [modernize-use-concise-preprocessor-directives]
125125
// CHECK-FIXES-ALL: #ifndef FOO
126126
#if !((!!(defined FOO)))
127-
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely [modernize-use-concise-preprocessor-directives]
127+
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using #elifdef [modernize-use-concise-preprocessor-directives]
128128
// CHECK-FIXES-23: #elifdef BAR
129129
#elif ((!(!(defined BAR))))
130130
#endif
131131

132132
#if FOO
133133
#elif BAR
134134
#endif
135+
136+
#if defined(FOO) && defined(BAR)
137+
#elif defined(FOO) && defined(BAR)
138+
#endif

0 commit comments

Comments
 (0)