43 const LangOptions &LO, SourceManager &SM,
46 bool canApply()
const {
return ConversionNotPossibleReason.empty(); }
48 return ConversionNotPossibleReason;
50 void applyFixes(DiagnosticBuilder &Diag, SourceManager &SM);
55 const Configuration
Config;
56 const bool CastMismatchedIntegerTypes;
57 const Expr *
const *Args;
58 const unsigned NumArgs;
60 const LangOptions &LangOpts;
61 std::string ConversionNotPossibleReason;
62 bool FormatStringNeededRewriting =
false;
63 bool UsePrintNewlineFunction =
false;
64 size_t PrintfFormatStringPos = 0U;
65 StringRef PrintfFormatString;
68 std::optional<ast_matchers::StatementMatcher> StringCStrCallExprMatcher;
70 const StringLiteral *FormatExpr;
71 std::string StandardFormatString;
79 explicit ArgumentFix(
unsigned ArgIndex, std::string
Fix)
83 std::vector<ArgumentFix> ArgFixes;
84 std::vector<ast_matchers::BoundNodes> ArgCStrRemovals;
89 std::vector<std::tuple<unsigned, unsigned>> ArgRotates;
93 void emitAlternativeForm(
const PrintfSpecifier &FS, std::string &FormatSpec);
94 void emitFieldWidth(
const PrintfSpecifier &FS, std::string &FormatSpec);
96 void emitStringArgument(
unsigned ArgIndex,
const Expr *Arg);
97 bool emitIntegerArgument(ConversionSpecifier::Kind ArgKind,
const Expr *Arg,
98 unsigned ArgIndex, std::string &FormatSpec);
101 std::string &FormatSpec);
103 std::string &StandardFormatString);
108 const char *StartSpecifier,
unsigned SpecifierLen,
109 const TargetInfo &Target)
override;
111 void appendFormatText(StringRef Text);
112 void finalizeFormatText();
113 static std::optional<StringRef>
114 formatStringContainsUnreplaceableMacro(
const CallExpr *CallExpr,
115 const StringLiteral *FormatExpr,
116 SourceManager &SM, Preprocessor &PP);
117 bool conversionNotPossible(std::string Reason) {
118 ConversionNotPossibleReason = std::move(Reason);
static cl::opt< bool > Fix("fix", desc(R"(
Apply suggested fixes. Without -fix-errors
clang-tidy will bail out if any compilation
errors were found.
)"), cl::init(false), cl::cat(ClangTidyCategory))
static cl::opt< std::string > Config("config", desc(R"(
Specifies a configuration in YAML/JSON format:
-config="{Checks:' *', CheckOptions:{x:y}}"
When the value is empty, clang-tidy will
attempt to find a file named .clang-tidy for
each source file in its parent directories.
)"), cl::init(""), cl::cat(ClangTidyCategory))