如何修复 Clang Tidy 中的 llvmlibc-restrict-system-libc-headers 检查?
How to fix llvmlibc-restrict-system-libc-headers check in Clang Tidy?
我不明白 Clang Tidy (link) 中的 llvmlibc-restrict-system-libc-headers
检查。
我像这样在 C++ 代码中包含 C 库:
#include <cstddef>
我应该更改什么来修复此 Clang Tidy 检查?它应该完全修复吗?
检查强制程序员使用提供的编译器 (libc) headers。
主要由开发llvm的libc的团队使用,以避免使用提供的系统headers。
来自 clang-tidy 项目的 Phabricator 网络界面:
This adds a new module to enforce standards specific to the llvm-libc project. This change also adds the first check which restricts user from including system libc headers accidentally which can lead to subtle bugs that would be a challenge to detect.
还有进一步
[...] I think the checker name should be generalized, as it does not need to be coupled with llvm-libc. Other projects may have similar needs. For example, they don't want to accidentally include a system zlib.h -> they may ship a bundled zlib (say, in third_party/zlib/).
Thanks for the suggestions, the general check sounds like a great idea. I can see the use case for this as it can be used by anyone. I took the time to port out fuchsia's check and flesh out the user facing documentation.
您可以通过在项目的包含目录中显式提供 intereset(这里是 libc headers)的 headers 并相应地调整链接路径来修复它。
要禁用它,您可以在 clang-tidy 的参数中指定不需要的检查。
CMake 示例:
set(CMAKE_C_CLANG_TIDY
clang-tidy;
-header-filter=.*;
-checks=*,-llvmlibc-restrict-system-libc-headers;
-warnings-as-errors=*;)
我不明白 Clang Tidy (link) 中的 llvmlibc-restrict-system-libc-headers
检查。
我像这样在 C++ 代码中包含 C 库:
#include <cstddef>
我应该更改什么来修复此 Clang Tidy 检查?它应该完全修复吗?
检查强制程序员使用提供的编译器 (libc) headers。
主要由开发llvm的libc的团队使用,以避免使用提供的系统headers。
来自 clang-tidy 项目的 Phabricator 网络界面:
This adds a new module to enforce standards specific to the llvm-libc project. This change also adds the first check which restricts user from including system libc headers accidentally which can lead to subtle bugs that would be a challenge to detect.
还有进一步
[...] I think the checker name should be generalized, as it does not need to be coupled with llvm-libc. Other projects may have similar needs. For example, they don't want to accidentally include a system zlib.h -> they may ship a bundled zlib (say, in third_party/zlib/).
Thanks for the suggestions, the general check sounds like a great idea. I can see the use case for this as it can be used by anyone. I took the time to port out fuchsia's check and flesh out the user facing documentation.
您可以通过在项目的包含目录中显式提供 intereset(这里是 libc headers)的 headers 并相应地调整链接路径来修复它。
要禁用它,您可以在 clang-tidy 的参数中指定不需要的检查。
CMake 示例:
set(CMAKE_C_CLANG_TIDY
clang-tidy;
-header-filter=.*;
-checks=*,-llvmlibc-restrict-system-libc-headers;
-warnings-as-errors=*;)