Skip to content

Commit

Permalink
Fix magic-numbers checker (#46)
Browse files Browse the repository at this point in the history
magic-numbers produced false-positives on compiler-generated code for defaulted member functions
  • Loading branch information
finomen authored Sep 27, 2022
1 parent 6453552 commit 5838797
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ void MagicNumbersCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}

void MagicNumbersCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(integerLiteral().bind("integer"), this);
Finder->addMatcher(traverse(TK_IgnoreUnlessSpelledInSource,
integerLiteral().bind("integer")),
this);
if (!IgnoreAllFloatingPointValues)
Finder->addMatcher(floatLiteral().bind("float"), this);
Finder->addMatcher(
traverse(TK_IgnoreUnlessSpelledInSource, floatLiteral().bind("float")),
this);
}

void MagicNumbersCheck::check(const MatchFinder::MatchResult &Result) {
Expand Down
4 changes: 0 additions & 4 deletions clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ class MagicNumbersCheck : public ClangTidyCheck {
CharSourceRange::getTokenRange(MatchedLiteral->getSourceRange()),
*Result.SourceManager, getLangOpts());

const auto parents = Result.Context->getParents(*MatchedLiteral);

const auto val = parents[0].template get<CallExpr>();

diag(MatchedLiteral->getLocation(),
"%0 is a magic number; consider replacing it with a named constant")
<< LiteralSourceText;
Expand Down

0 comments on commit 5838797

Please sign in to comment.