Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ class IfPreprocessorCallbacks final : public PPCallbacks {
Check.diag(
DirectiveLoc,
"preprocessor condition can be written more concisely using '#%0'")
<< FixItHint::CreateReplacement(DirectiveLoc, Replacements[Inverted])
<< FixItHint::CreateReplacement(
CharSourceRange::getCharRange(DirectiveLoc,
ConditionRange.getBegin()),
(Replacements[Inverted].str() + " "))
<< FixItHint::CreateReplacement(ConditionRange, Macro)
<< Replacements[Inverted];
}
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ Changes in existing checks
<clang-tidy/checks/readability/uppercase-literal-suffix>` check to recognize
literal suffixes added in C++23 and C23.

- Improved :doc:`readability-use-concise-preprocessor-directives
<clang-tidy/checks/readability/use-concise-preprocessor-directives>` check to
generate correct fix-its for forms without a space after the directive.

Removed checks
^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
# elif (defined(BAR))
#endif

// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
// CHECK-FIXES: #ifdef FOO
#if(defined(FOO))
// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
// CHECK-FIXES-23: #elifdef BAR
#elif(defined(BAR))
#endif

// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
// CHECK-FIXES: #ifdef FOO
#if (defined FOO)
Expand Down