11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 20 void MisplacedConstCheck::registerMatchers(MatchFinder *Finder) {
22 valueDecl(hasType(isConstQualified()),
23 hasType(typedefType(hasDeclaration(
24 typedefDecl(hasType(pointerType(unless(pointee(
25 anyOf(isConstQualified(),
26 ignoringParens(functionType())))))))
36 if (!QT->isPointerType())
39 Qualifiers Quals = QT.getLocalQualifiers();
42 QualType NewQT = Context.getPointerType(
43 QualType(QT->getPointeeType().getTypePtr(), Qualifiers::Const));
44 return NewQT.withCVRQualifiers(Quals.getCVRQualifiers());
47 void MisplacedConstCheck::check(
const MatchFinder::MatchResult &
Result) {
48 const auto *Var = Result.Nodes.getNodeAs<ValueDecl>(
"decl");
49 const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>(
"typedef");
50 ASTContext &
Ctx = *Result.Context;
51 QualType CanQT = Var->getType().getCanonicalType();
53 diag(Var->getLocation(),
"%0 declared with a const-qualified typedef type; " 54 "results in the type being '%1' instead of '%2'")
55 << Var << CanQT.getAsString(Ctx.getPrintingPolicy())
57 .getAsString(Ctx.getPrintingPolicy());
58 diag(Typedef->getLocation(),
"typedef declared here", DiagnosticIDs::Note);
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static QualType guessAlternateQualification(ASTContext &Context, QualType QT)