33 const DynTypedNodeList ConstructParents =
34 Ctx.getParentMapContext().getParents(*FoundConstructExpr);
35 if (ConstructParents.size() != 1)
37 const auto *ParentDecl = ConstructParents.begin()->get<DeclaratorDecl>();
38 if (isa_and_nonnull<VarDecl, FieldDecl>(ParentDecl))
57 auto FindConstructor =
59 parameterCountIs(1), isExplicit())
61 auto FindConstructExpr =
63 hasDeclaration(FindConstructor), argumentCountIs(1),
66 hasType(hasCanonicalType(pointerType(
70 Finder->addMatcher(FindConstructExpr,
this);
74 const auto *FoundNewExpr = Result.Nodes.getNodeAs<CXXNewExpr>(
NewExprN);
75 const auto *FoundConstructExpr =
77 const auto *FoundConstructorDecl =
78 Result.Nodes.getNodeAs<CXXConstructorDecl>(
ConstructorN);
80 ASTContext &Ctx = FoundConstructorDecl->getASTContext();
81 const DeclaratorDecl *VarOrField =
84 auto D = diag(FoundNewExpr->getBeginLoc(),
85 "%0 pointer to non-array is initialized with array")
87 D << FoundNewExpr->getSourceRange();
90 auto TSTypeLoc = VarOrField->getTypeSourceInfo()
92 .getAsAdjusted<clang::TemplateSpecializationTypeLoc>();
93 assert(TSTypeLoc.getNumArgs() >= 1 &&
94 "Matched type should have at least 1 template argument.");
96 const SourceRange TemplateArgumentRange = TSTypeLoc.getArgLoc(0)
100 D << TemplateArgumentRange;
103 const SourceManager &SM = Ctx.getSourceManager();
107 const SourceLocation InsertLoc = Lexer::getLocForEndOfToken(
108 TemplateArgumentRange.getEnd(), 0, SM, Ctx.getLangOpts());
109 D << FixItHint::CreateInsertion(InsertLoc,
"[]");
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.