Mercurial > hg > CbC > CbC_llvm
diff clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp @ 173:0572611fdcc8 llvm10 llvm12
reorgnization done
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 11:55:54 +0900 |
parents | 1d019706d866 |
children | 2e18cbf3894f |
line wrap: on
line diff
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp Mon May 25 11:50:15 2020 +0900 +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp Mon May 25 11:55:54 2020 +0900 @@ -39,9 +39,6 @@ /// Match common cases, where the owner semantic is relevant, like function /// calls, delete expressions and others. void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) { - if (!getLangOpts().CPlusPlus11) - return; - const auto OwnerDecl = typeAliasTemplateDecl(hasName("::gsl::owner")); const auto IsOwnerType = hasType(OwnerDecl); @@ -72,10 +69,10 @@ // Find delete expressions that delete non-owners. Finder->addMatcher( - cxxDeleteExpr( - hasDescendant( - declRefExpr(unless(ConsideredOwner)).bind("deleted_variable"))) - .bind("delete_expr"), + traverse(ast_type_traits::TK_AsIs, + cxxDeleteExpr(hasDescendant(declRefExpr(unless(ConsideredOwner)) + .bind("deleted_variable"))) + .bind("delete_expr")), this); // Ignoring the implicit casts is vital because the legacy owners do not work @@ -86,24 +83,29 @@ // resources. This check assumes that all pointer arguments of a legacy // functions shall be 'gsl::owner<>'. Finder->addMatcher( - callExpr(callee(LegacyOwnerConsumers), - hasAnyArgument(expr(unless(ignoringImpCasts(ConsideredOwner)), - hasType(pointerType())))) - .bind("legacy_consumer"), + traverse(ast_type_traits::TK_AsIs, + callExpr(callee(LegacyOwnerConsumers), + hasAnyArgument( + expr(unless(ignoringImpCasts(ConsideredOwner)), + hasType(pointerType())))) + .bind("legacy_consumer")), this); // Matching assignment to owners, with the rhs not being an owner nor creating // one. - Finder->addMatcher(binaryOperator(matchers::isAssignmentOperator(), - hasLHS(IsOwnerType), - hasRHS(unless(ConsideredOwner))) - .bind("owner_assignment"), - this); + Finder->addMatcher( + traverse(ast_type_traits::TK_AsIs, + binaryOperator(isAssignmentOperator(), hasLHS(IsOwnerType), + hasRHS(unless(ConsideredOwner))) + .bind("owner_assignment")), + this); // Matching initialization of owners with non-owners, nor creating owners. Finder->addMatcher( - namedDecl(varDecl(hasInitializer(unless(ConsideredOwner)), IsOwnerType) - .bind("owner_initialization")), + traverse(ast_type_traits::TK_AsIs, + namedDecl( + varDecl(hasInitializer(unless(ConsideredOwner)), IsOwnerType) + .bind("owner_initialization"))), this); const auto HasConstructorInitializerForOwner = @@ -118,11 +120,13 @@ // Match class member initialization that expects owners, but does not get // them. - Finder->addMatcher(cxxRecordDecl(HasConstructorInitializerForOwner), this); + Finder->addMatcher(traverse(ast_type_traits::TK_AsIs, + cxxRecordDecl(HasConstructorInitializerForOwner)), + this); // Matching on assignment operations where the RHS is a newly created owner, // but the LHS is not an owner. - Finder->addMatcher(binaryOperator(matchers::isAssignmentOperator(), + Finder->addMatcher(binaryOperator(isAssignmentOperator(), hasLHS(unless(IsOwnerType)), hasRHS(CreatesOwner)) .bind("bad_owner_creation_assignment"), @@ -131,11 +135,14 @@ // Matching on initialization operations where the initial value is a newly // created owner, but the LHS is not an owner. Finder->addMatcher( - namedDecl(varDecl(eachOf(allOf(hasInitializer(CreatesOwner), - unless(IsOwnerType)), - allOf(hasInitializer(ConsideredOwner), - hasType(autoType().bind("deduced_type"))))) - .bind("bad_owner_creation_variable")), + traverse( + ast_type_traits::TK_AsIs, + namedDecl( + varDecl(eachOf(allOf(hasInitializer(CreatesOwner), + unless(IsOwnerType)), + allOf(hasInitializer(ConsideredOwner), + hasType(autoType().bind("deduced_type"))))) + .bind("bad_owner_creation_variable"))), this); // Match on all function calls that expect owners as arguments, but didn't @@ -219,7 +226,7 @@ // Result of matching for legacy consumer-functions like `::free()`. const auto *LegacyConsumer = Nodes.getNodeAs<CallExpr>("legacy_consumer"); - // FIXME: `freopen` should be handled seperately because it takes the filename + // FIXME: `freopen` should be handled separately because it takes the filename // as a pointer, which should not be an owner. The argument that is an owner // is known and the false positive coming from the filename can be avoided. if (LegacyConsumer) {