简体   繁体   中英

Do Clang vs Clang tidy detect the same warnings and errors ?

As far as I know the Clan-tidy can do these checks https://clang.llvm.org/extra/clang-tidy/checks/list.html over and above default checks set (clang-analyser) and Clang can also detect errors and warnings https://clang.llvm.org/docs/DiagnosticsReference.html Can they detect different list of errors or warnings ?
Does the Clang-Tidy use Clang in background ? Is there any connection between both ?

Yes, their is a difference and a common ground. Let me start with the common ground: both of them are part of the LLVM project, which is know to provide libraries and executables build on top of it.

In this case, the clang compiler uses the frontend to create an AST and creates the compiler warnings at that time. It is extended with optimizations and codegen.

Clang-tidy uses the same frontend and than runs AST matchers on it to detect issues.

In general, compiler warnings are cheap to check and contain (almost) no false positives. Clang-tidy has the expensive checks or the ones with more risk on false positives. The later also contains less common checks, or stylistic checks.

Some checks are indeed similar, for example the missing override, however, tidy catches all cases, where the warning is suppressed when override isn't used in the file.

In general, I like to enable all warnings and disable the ones that should be fixed later on. This will be checked as side effect when compiling. Clang-tidy usually get ran later in the progress (precommit or CI).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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