Skip to content

Commit

Permalink
[clang-tidy] Fix RenamerClangTidyChecks suggesting invalid macro iden…
Browse files Browse the repository at this point in the history
…tifiers

This behavior was fixed for regular identifiers in
9f3edc3, but the same fix was not applied to
macro fixits. This addresses #52895.

Differential Revision: https://reviews.llvm.org/D116824
  • Loading branch information
kepler-5 committed Jan 10, 2022
1 parent 68468bb commit 988c3f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
Expand Up @@ -486,6 +486,9 @@ void RenamerClangTidyCheck::checkMacro(SourceManager &SourceMgr,
NamingCheckFailure &Failure = NamingCheckFailures[ID];
SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());

if (!isValidAsciiIdentifier(Info.Fixup))
Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;

Failure.Info = std::move(Info);
addUsage(ID, Range);
}
Expand Down
Expand Up @@ -171,6 +171,11 @@ int _;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_', which is reserved in the global namespace; cannot be fixed automatically [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}int _;{{$}}

// https://github.com/llvm/llvm-project/issues/52895
#define _5_kmph_rpm 459
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '_5_kmph_rpm', which is reserved in the global namespace; cannot be fixed automatically [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}#define _5_kmph_rpm 459{{$}}

// these should pass
#define MACRO(m) int m = 0

Expand Down

0 comments on commit 988c3f5

Please sign in to comment.