usage_restriction_checks.cpp 1.2 KB

123456789101112131415161718192021222324
  1. #include "usage_restriction_checks.h"
  2. #include <contrib/libs/clang16/include/clang/AST/ASTContext.h>
  3. #include <contrib/libs/clang16/include/clang/ASTMatchers/ASTMatchFinder.h>
  4. using namespace clang::ast_matchers;
  5. namespace clang::tidy::arcadia {
  6. void TypeidNameRestrictionCheck::registerMatchers(MatchFinder* Finder) {
  7. Finder->addMatcher(cxxMemberCallExpr(on(expr(hasType(namedDecl(hasName("::std::type_info")))).bind("expr")),
  8. callee(cxxMethodDecl(hasName("name"), parameterCountIs(0)))),
  9. this);
  10. Finder->addMatcher(cxxMemberCallExpr(on(expr(hasType(namedDecl(hasName("::std::type_index")))).bind("expr")),
  11. callee(cxxMethodDecl(hasName("name"), parameterCountIs(0)))),
  12. this);
  13. }
  14. void TypeidNameRestrictionCheck::check(const MatchFinder::MatchResult& Result) {
  15. const auto node = Result.Nodes.getNodeAs<Expr>("expr");
  16. diag(node->getBeginLoc(), "Both std::type_info::name() and std::type_index::name() return mangled typename. "
  17. "Consider using TypeName() functions from <util/system/type_name.h> instead");
  18. }
  19. }