================ @@ -0,0 +1,96 @@ +//===--- IncorrectEnableSharedFromThisCheck.cpp - clang-tidy +//-------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "IncorrectEnableSharedFromThisCheck.h" +#include "clang/AST/DeclCXX.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +void IncorrectEnableSharedFromThisCheck::registerMatchers( + MatchFinder *match_finder) { + match_finder->addMatcher( + cxxRecordDecl( + unless(isExpansionInSystemHeader()), + hasAnyBase(cxxBaseSpecifier(unless(isPublic()), + hasType(cxxRecordDecl(hasName( + "::std::enable_shared_from_this")))))) + .bind("class-base-std-enable"), + this); + match_finder->addMatcher( + cxxRecordDecl(unless(isExpansionInSystemHeader()), + hasAnyBase(cxxBaseSpecifier(hasType( + cxxRecordDecl(hasName("enable_shared_from_this")))))) + .bind("class-missing-std"), + this); +} + +void IncorrectEnableSharedFromThisCheck::check( + const MatchFinder::MatchResult &result) { + const auto *StdEnableSharedClassDecl = + result.Nodes.getNodeAs<CXXRecordDecl>("class-base-std-enable"); + const auto *MissingStdSharedClassDecl = + result.Nodes.getNodeAs<CXXRecordDecl>("class-missing-std"); + + if (StdEnableSharedClassDecl) { + for (const CXXBaseSpecifier &Base : StdEnableSharedClassDecl->bases()) { + const CXXRecordDecl *BaseType = Base.getType()->getAsCXXRecordDecl(); + if (BaseType && BaseType->getQualifiedNameAsString() == + "std::enable_shared_from_this") { + SourceRange ReplacementRange = Base.getSourceRange(); + std::string ReplacementString = ---------------- MichelleCDjunaidi wrote:
Ran and fixed https://github.com/llvm/llvm-project/pull/102299 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits