11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 21 {
"::std::ios_base::io_state"},
22 {
"::std::ios_base::open_mode"},
23 {
"::std::ios_base::seek_dir"},
24 {
"::std::ios_base::streamoff"},
25 {
"::std::ios_base::streampos"}};
28 {
"io_state",
"iostate"},
29 {
"open_mode",
"openmode"},
30 {
"seek_dir",
"seekdir"}};
32 void DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) {
35 if (!getLangOpts().CPlusPlus)
38 auto IoStateDecl = typedefDecl(hasAnyName(DeprecatedTypes)).bind(
"TypeDecl");
40 qualType(hasDeclaration(IoStateDecl), unless(elaboratedType()));
42 Finder->addMatcher(typeLoc(loc(IoStateType)).bind(
"TypeLoc"),
this);
45 void DeprecatedIosBaseAliasesCheck::check(
46 const MatchFinder::MatchResult &
Result) {
47 SourceManager &SM = *Result.SourceManager;
49 const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>(
"TypeDecl");
50 StringRef TypeName = Typedef->getName();
51 bool HasReplacement = ReplacementTypes.count(TypeName);
53 const auto *TL = Result.Nodes.getNodeAs<TypeLoc>(
"TypeLoc");
54 SourceLocation IoStateLoc = TL->getBeginLoc();
58 bool Fix = HasReplacement && !TL->getType()->isDependentType();
59 if (IoStateLoc.isMacroID()) {
60 IoStateLoc = SM.getSpellingLoc(IoStateLoc);
64 SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1);
67 auto FixName = ReplacementTypes.lookup(TypeName);
68 auto Builder = diag(IoStateLoc,
"'std::ios_base::%0' is deprecated; use " 69 "'std::ios_base::%1' instead")
70 << TypeName << FixName;
73 Builder << FixItHint::CreateReplacement(SourceRange(IoStateLoc, EndLoc),
76 diag(IoStateLoc,
"'std::ios_base::%0' is deprecated") << TypeName;
static const llvm::StringMap< StringRef > ReplacementTypes
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
static const llvm::SmallVector< StringRef, 5 > DeprecatedTypes
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static cl::opt< bool > Fix("fix", cl::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))