10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
18 const QualType PtrType =
Type->getPointeeType();
19 if (!PtrType.isNull())
22 return Type.isConstQualified();
26 const QualType PtrType =
Type->getPointeeType();
27 if (!PtrType.isNull())
29 return Type.isVolatileQualified();
35 StrictMode(Options.getLocalOrGlobal(
"StrictMode", false)) {}
42 Finder->addMatcher(cxxConstCastExpr().bind(
"cast"),
this);
46 const auto *MatchedCast = Result.Nodes.getNodeAs<CXXConstCastExpr>(
"cast");
48 diag(MatchedCast->getOperatorLoc(),
"do not use const_cast");
52 const QualType TargetType = MatchedCast->getType().getCanonicalType();
53 const QualType SourceType =
54 MatchedCast->getSubExpr()->getType().getCanonicalType();
56 const bool RemovingConst =
58 const bool RemovingVolatile =
61 if (!RemovingConst && !RemovingVolatile) {
66 diag(MatchedCast->getOperatorLoc(),
67 "do not use const_cast to remove%select{| const}0%select{| "
68 "and}2%select{| volatile}1 qualifier")
69 << RemovingConst << RemovingVolatile
70 << (RemovingConst && RemovingVolatile);
llvm::SmallString< 256U > Name
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
ProTypeConstCastCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
static bool hasConstQualifier(QualType Type)
static bool hasVolatileQualifier(QualType Type)
llvm::StringMap< ClangTidyValue > OptionMap