lix/subprojects/lix-clang-tidy/CharPtrCast.hh
Jade Lovelace a5f0954c29 clang-tidy: write a lint for charptr_cast
This lets us ensure that nobody is putting in new reinterpret_cast
instances where they could safely use charptr_cast instead.

Change-Id: I6358a3934c8133c7150042635843bdbb6b9218d4
2024-08-08 14:53:17 -07:00

32 lines
950 B
C++

#pragma once
///@file
#include <clang-tidy/ClangTidyCheck.h>
#include <clang-tidy/utils/IncludeInserter.h>
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>
namespace nix::clang_tidy {
using namespace clang;
using namespace clang::tidy;
class CharPtrCastCheck : public ClangTidyCheck {
tidy::utils::IncludeInserter Inserter{
Options.getLocalOrGlobal("IncludeStyle",
tidy::utils::IncludeSorter::IS_Google),
false};
public:
CharPtrCastCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerPPCallbacks(const SourceManager &, Preprocessor *PP,
Preprocessor *) override {
Inserter.registerPreprocessor(PP);
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
} // namespace nix::clang_tidy