我有几张定制的干净支票。例如,一个在cppcoreguidelines模块中,另一个在misc模块中。他们工作得很好。现在,我通过自定义模块扩展clang,将它们组织起来。
当我重新构建时,它会成功,但是当我运行./clang-tidy -list-checks -checks=*时,我的检查将不会出现。
下面是我在添加名为sw的自定义模块时所做的工作
sw下创建了一个子目录/clang-tools-extra/clang-tidy//clang-tools-extra/clang-tidy/CMakeLists.txt:- adding `add_subdirectory(sw)` right below `add_subdirectory(readability)`
- listing `clangTidySWModule` inside the `set(ALL_CLANG_TIDY_CHECKS ...)` command/clang-tools-extra/clang-tidy/sw/CMakeLists.txt:set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
)
add_clang_library(clangTidySWModule
AllCapsEnumeratorsCheck.cpp
CatchByConstReferenceCheck.cpp
SWTidyModule.cpp
LINK_LIBS
clangTidy
clangTidyUtils
DEPENDS
omp_gen
)
clang_target_link_libraries(clangTidySWModule
PRIVATE
clangAnalysis
clangAST
clangASTMatchers
clangBasic
clangLex
clangTooling
)/clang-tools-extra/clang-tidy/sw/SWTidyModule.cpp:#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "AllCapsEnumeratorsCheck.h"
#include "CatchByConstReferenceCheck.h"
namespace clang {
namespace tidy {
namespace sw {
class SWModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<AllCapsEnumeratorsCheck>(
"sw-all-caps-enumerators");
CheckFactories.registerCheck<CatchByConstReferenceCheck>(
"sw-catch-by-const-reference");
}
};
// Register the SWModule using this statically initialized variable.
static ClangTidyModuleRegistry::Add<SWModule>
X("sw-module", "Adds my custom checks.");
} // namespace sw
// This anchor is used to force the linker to link in the generated object file
// and thus register the ReadabilityModule.
volatile int SWModuleAnchorSource = 0;
} // namespace tidy
} // namespace clang我添加了两个检查( all-caps-enumerators和catch-by-const-reference ),就像之前在其他模块下所做的那样:
python3 add_new_check.py sw all-caps-enumerators
python3 add_new_check.py sw catch-by-const-reference我是不是遗漏了什么?为什么我的支票没出现?
发布于 2022-08-30 15:18:44
我找到了我所缺少的这里。希望这篇文章至少能帮助其他人更快地找到答案,再加上准确地添加缺失部分的位置。
我在/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h中错过了下面的内容
// This anchor is used to force the linker to link the SWModule.
extern volatile int SWModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED SWModuleAnchorDestination =
SWModuleAnchorSource;现在我的支票出现了,我很高兴(:
https://stackoverflow.com/questions/73531240
复制相似问题