28 mapAnyOf(cxxConstructExpr, cxxUnresolvedConstructExpr)
29 .with(hasParent(compoundStmt().bind(
"compound")),
30 anyOf(hasType(hasCanonicalType(recordType(hasDeclaration(
31 cxxRecordDecl(hasNonTrivialDestructor()))))),
32 hasType(hasCanonicalType(templateSpecializationType(
33 hasDeclaration(classTemplateDecl(has(
34 cxxRecordDecl(hasNonTrivialDestructor())))))))))
59 const auto *E = Result.Nodes.getNodeAs<Expr>(
"expr");
63 if (E->getBeginLoc().isMacroID())
68 const auto *CS = Result.Nodes.getNodeAs<CompoundStmt>(
"compound");
69 const auto *LastExpr = dyn_cast<Expr>(CS->body_back());
71 if (LastExpr && E == LastExpr->IgnoreUnlessSpelledInSource())
76 diag(E->getBeginLoc(),
"object destroyed immediately after "
77 "creation; did you mean to name the object?");
79 if (
const auto *Node = dyn_cast<CXXConstructExpr>(E))
81 Node->getNumArgs() == 0 ||
82 isa<CXXDefaultArgExpr>(Node->getArg(0)));
83 if (
const auto *Node = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
84 auto SR = SourceRange(Node->getLParenLoc(), Node->getRParenLoc());
85 auto DefaultConstruction = Node->getNumArgs() == 0;
86 if (!DefaultConstruction) {
87 auto *FirstArg = Node->getArg(0);
88 DefaultConstruction = isa<CXXDefaultArgExpr>(FirstArg);
89 if (
auto *ILE = dyn_cast<InitListExpr>(FirstArg)) {
90 DefaultConstruction = ILE->getNumInits() == 0;
91 SR = SourceRange(ILE->getLBraceLoc(), ILE->getRBraceLoc());