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);
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.