aboutsummaryrefslogtreecommitdiff
path: root/subprojects/lix-clang-tidy/CharPtrCast.hh
diff options
context:
space:
mode:
authorJade Lovelace <lix@jade.fyi>2024-08-04 22:02:53 -0700
committerJade Lovelace <lix@jade.fyi>2024-08-08 14:53:17 -0700
commita5f0954c290157875b4dfb79edcf651f55742dc2 (patch)
tree16efd430c4c0828ee236eda636015e79e15bb965 /subprojects/lix-clang-tidy/CharPtrCast.hh
parenta85c4ce535c940bd2f48c34ab823fb3a8f5be0cc (diff)
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
Diffstat (limited to 'subprojects/lix-clang-tidy/CharPtrCast.hh')
-rw-r--r--subprojects/lix-clang-tidy/CharPtrCast.hh32
1 files changed, 32 insertions, 0 deletions
diff --git a/subprojects/lix-clang-tidy/CharPtrCast.hh b/subprojects/lix-clang-tidy/CharPtrCast.hh
new file mode 100644
index 000000000..66883d055
--- /dev/null
+++ b/subprojects/lix-clang-tidy/CharPtrCast.hh
@@ -0,0 +1,32 @@
+#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