12#include "clang/AST/ASTContext.h"
13#include "clang/ASTMatchers/ASTMatchFinder.h"
14#include "llvm/ADT/STLExtras.h"
23constexpr llvm::StringLiteral DeprecatedCheckName =
"zircon-temporary-objects";
24constexpr llvm::StringLiteral CanonicalCheckName =
"fuchsia-temporary-objects";
26AST_MATCHER_P(CXXRecordDecl, matchesAnyName, ArrayRef<StringRef>, Names) {
27 const std::string QualifiedName = Node.getQualifiedNameAsString();
28 return llvm::is_contained(Names, QualifiedName);
36 Names(
utils::options::parseStringList(Options.get(
"Names",
""))) {
37 if (Name == DeprecatedCheckName)
45 cxxTemporaryObjectExpr(hasDeclaration(cxxConstructorDecl(hasParent(
46 cxxRecordDecl(matchesAnyName(Names))))))
53 cxxConstructExpr(hasParent(cxxFunctionalCastExpr()),
54 hasDeclaration(cxxConstructorDecl(hasParent(
55 cxxRecordDecl(matchesAnyName(Names))))))
61 if (
const auto *D = Result.Nodes.getNodeAs<CXXConstructExpr>(
"temps"))
62 diag(D->getLocation(),
63 "creating a temporary object of type %q0 is prohibited")
64 << D->getConstructor()->getParent();
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
TemporaryObjectsCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
AST_MATCHER_P(Stmt, isStatementIdenticalToBoundNode, std::string, ID)
std::string serializeStringList(ArrayRef< StringRef > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
void diagDeprecatedCheckAlias(ClangTidyCheck &Check, const ClangTidyContext &Context, StringRef DeprecatedName, StringRef CanonicalName)
Emits a configuration diagnostic when a deprecated check alias is enabled and the canonical check nam...
llvm::StringMap< ClangTidyValue > OptionMap