10 #include "../utils/OptionsUtils.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "llvm/ADT/STLExtras.h"
14 #include "llvm/ADT/SmallVector.h"
23 AST_MATCHER_P(CXXRecordDecl, matchesAnyName, ArrayRef<std::string>, Names) {
24 std::string QualifiedName = Node.getQualifiedNameAsString();
25 return llvm::any_of(Names,
26 [&](StringRef
Name) {
return QualifiedName ==
Name; });
29 void TemporaryObjectsCheck::registerMatchers(MatchFinder *Finder) {
32 cxxTemporaryObjectExpr(hasDeclaration(cxxConstructorDecl(hasParent(
33 cxxRecordDecl(matchesAnyName(Names))))))
39 traverse(ast_type_traits::TK_AsIs,
40 cxxConstructExpr(hasParent(cxxFunctionalCastExpr()),
41 hasDeclaration(cxxConstructorDecl(hasParent(
42 cxxRecordDecl(matchesAnyName(Names))))))
47 void TemporaryObjectsCheck::check(
const MatchFinder::MatchResult &Result) {
48 if (
const auto *D = Result.Nodes.getNodeAs<CXXConstructExpr>(
"temps"))
49 diag(D->getLocation(),
50 "creating a temporary object of type %q0 is prohibited")
51 << D->getConstructor()->getParent();