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