aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/clang_tidy/arcadia_checks/usage_restriction_checks.cpp
blob: b453008807638c5786eb78a3b06d9ba122c9d693 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "usage_restriction_checks.h"
#include <contrib/libs/clang16/include/clang/AST/ASTContext.h>
#include <contrib/libs/clang16/include/clang/ASTMatchers/ASTMatchFinder.h>

using namespace clang::ast_matchers;

namespace clang::tidy::arcadia {
    void TypeidNameRestrictionCheck::registerMatchers(MatchFinder* Finder) {
        Finder->addMatcher(cxxMemberCallExpr(on(expr(hasType(namedDecl(hasName("::std::type_info")))).bind("expr")),
                                             callee(cxxMethodDecl(hasName("name"), parameterCountIs(0)))),
                           this);
        Finder->addMatcher(cxxMemberCallExpr(on(expr(hasType(namedDecl(hasName("::std::type_index")))).bind("expr")),
                                             callee(cxxMethodDecl(hasName("name"), parameterCountIs(0)))),
                           this);
    }

    void TypeidNameRestrictionCheck::check(const MatchFinder::MatchResult& Result) {
        const auto node = Result.Nodes.getNodeAs<Expr>("expr");

        diag(node->getBeginLoc(), "Both std::type_info::name() and std::type_index::name() return mangled typename. "
                                  "Consider using TypeName() functions from <util/system/type_name.h> instead");
    }

}