28 void check(
const ast_matchers::MatchFinder::MatchResult &Result)
override;
31 bool isConstant(
const ast_matchers::MatchFinder::MatchResult &Result,
32 const Expr &ExprResult)
const;
34 bool isIgnoredValue(
const IntegerLiteral *Literal)
const;
35 bool isIgnoredValue(
const FloatingLiteral *Literal)
const;
37 bool isSyntheticValue(
const SourceManager *,
const FloatingLiteral *)
const {
40 bool isSyntheticValue(
const SourceManager *SourceManager,
41 const IntegerLiteral *Literal)
const;
43 bool isBitFieldWidth(
const ast_matchers::MatchFinder::MatchResult &,
44 const FloatingLiteral &)
const {
48 bool isBitFieldWidth(
const ast_matchers::MatchFinder::MatchResult &Result,
49 const IntegerLiteral &Literal)
const;
52 isUserDefinedLiteral(
const ast_matchers::MatchFinder::MatchResult &Result,
53 const Expr &Literal)
const;
56 void checkBoundMatch(
const ast_matchers::MatchFinder::MatchResult &Result,
57 const char *BoundName) {
58 const L *MatchedLiteral = Result.Nodes.getNodeAs<L>(BoundName);
62 if (Result.SourceManager->isMacroBodyExpansion(
63 MatchedLiteral->getLocation()))
66 if (isIgnoredValue(MatchedLiteral))
69 if (isConstant(Result, *MatchedLiteral))
72 if (isSyntheticValue(Result.SourceManager, MatchedLiteral))
75 if (isBitFieldWidth(Result, *MatchedLiteral))
78 if (IgnoreUserDefinedLiterals &&
79 isUserDefinedLiteral(Result, *MatchedLiteral))
82 const StringRef LiteralSourceText = Lexer::getSourceText(
83 CharSourceRange::getTokenRange(MatchedLiteral->getSourceRange()),
84 *Result.SourceManager, getLangOpts());
86 diag(MatchedLiteral->getLocation(),
87 "%0 is a magic number; consider replacing it with a named constant")
91 const bool IgnoreAllFloatingPointValues;
92 const bool IgnoreBitFieldsWidths;
93 const bool IgnorePowersOf2IntegerValues;
94 const bool IgnoreTypeAliases;
95 const bool IgnoreUserDefinedLiterals;
96 const StringRef RawIgnoredIntegerValues;
97 const StringRef RawIgnoredFloatingPointValues;
99 constexpr static unsigned SensibleNumberOfMagicValueExceptions = 16;
101 constexpr static llvm::APFloat::roundingMode DefaultRoundingMode =
102 llvm::APFloat::rmNearestTiesToEven;
105 IgnoredIntegerValues;
107 IgnoredFloatingPointValues;
109 IgnoredDoublePointValues;
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.