繁体   English   中英

c++ clang-tidy 给出与 llvm-libc 相关的错误

[英]c++ clang-tidy gives errors related to llvm-libc

我在本地计算机上工作时遇到了麻烦。 我的代码充满了这三个错误:

error: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace,-warnings-as-errors]

error: 'connect2AtLevel' must resolve to a function declared within the '__llvm_libc' namespace [llvmlibc-callee-namespace,-warnings-as-errors]

error: system include cassert not allowed [llvmlibc-restrict-system-libc-headers,-warnings-as-errors]

我阅读了这些错误的解释,但我仍然不明白我需要做什么。 这似乎与llvm中可用的标头有关? 我通常使用 gcc 中包含的 libstdc++,我需要使用 llvm 库吗? 例如,如果我想使用 cassert,将这些错误发送到 go 会是什么样子? 如果我能解决这个问题,我宁愿不只是在 my.clang-tidy 中添加一些东西。

编辑:这是要求的附加信息。

程序版本: GCC 11.1.0: libstdc++.so.6.0.29

LLVM version 13.0.0

clang-tidy 运行: clang-tidy *.cpp -std=c++11

这是.clang-tidy的内容:(该文件是使用旧版本的 LLVM 提供的,应该如何更新HeaderFilterRegex ?):


WarningsAsErrors:  '*'                                                                     
HeaderFilterRegex: '.*'                                                                    
                                                                                           
CheckOptions:                                                                              
 { key: readability-identifier-naming.ClassCase,           value: CamelCase  }           
 { key: readability-identifier-naming.StructCase,          value: CamelCase  }           
 { key: readability-identifier-naming.EnumCase,            value: CamelCase  }           
 { key: readability-identifier-naming.GlobalConstantCase,  value: UPPER_CASE }           
                                                                                         
 { key: readability-identifier-naming.VariableCase,        value: camelBack  }           
 { key: readability-identifier-naming.ParameterCase,       value: camelBack  }           
 { key: readability-identifier-naming.PublicMemberCase,    value: camelBack  }

clang-tidy 由几个模块组成,可以通过多种方式激活或停用。 您可以使用所有这些,不使用它们或其中一些。 这是当前的检查列表:

Name prefix     Description
abseil-     Checks related to Abseil library.
altera-     Checks related to OpenCL programming for FPGAs.
android-    Checks related to Android.
boost-      Checks related to Boost library.
bugprone-   Checks that target bug-prone code constructs.
cert-       Checks related to CERT Secure Coding Guidelines.
clang-analyzer-     Clang Static Analyzer checks.
concurrency-    Checks related to concurrent programming (including threads, fibers, coroutines, etc.).
cppcoreguidelines-  Checks related to C++ Core Guidelines.
darwin-     Checks related to Darwin coding conventions.
fuchsia-    Checks related to Fuchsia coding conventions.
google-     Checks related to Google coding conventions.
hicpp-      Checks related to High Integrity C++ Coding Standard.
linuxkernel-    Checks related to the Linux Kernel coding conventions.
llvm-       Checks related to the LLVM coding conventions.
llvmlibc-   Checks related to the LLVM-libc coding standards.
misc-       Checks that we didn’t have a better category for.
modernize-  Checks that advocate usage of modern (currently “modern” means “C++11”) language constructs.
mpi-        Checks related to MPI (Message Passing Interface).
objc-       Checks related to Objective-C coding conventions.
openmp-     Checks related to OpenMP API.
performance-    Checks that target performance-related issues.
portability-    Checks that target portability-related issues that don’t relate to any particular coding style.
readability-    Checks that target readability-related issues that don’t relate to any particular coding style.
zircon-     Checks related to Zircon kernel coding conventions.

clang-tidy 的模块有时非常迂腐和过度。 它们中的每一个都是由给定的团队创建的,并且服务的目的不一定与您的一致。 以下是模块的完整列表:

https://clang.llvm.org/extra/clang-tidy/checks/list.html

到 select 什么模块和检查到 select 为您的代码,您可以在命令行上传递一个类似查询的字符串,或者(更容易)在项目的根目录中放置一个.clang-tidy文件。 这是我的:

---
Checks:          '-*,clang-diagnostic-*,-clang-diagnostic-unused-value,clang-analyzer-*,-*,bugprone-*,performance-*,readability-*,-readability-magic-numbers,-readability-braces-around-statements,-readability-inconsistent-declaration-parameter-name,-readability-named-parameter'
HeaderFilterRegex: ''
WarningsAsErrors: '*'
AnalyzeTemporaryDtors: false
...

要转储默认配置,请执行以下操作:

$ clang-tidy -dump-config > .clang-tidy

clang-tidy 的手册页有更多信息:

http://manpages.ubuntu.com/manpages/focal/man1/clang-tidy-6.0.1.html

这是一般的clang-tidy文档: https://clang.llvm.org/extra/clang-tidy/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM