Questions tagged [clang-tidy]

For questions about clang-tidy as a static analyzer and code modernization tool. For more generic questions such as compiler diagnostic messages use the clang tag.

404 questions
66
votes
3 answers

"Use of a signed integer operand with a binary bitwise operator" - when using unsigned short

In the following C snippet that checks if the first two bits of a 16-bit sequence are set: bool is_pointer(unsigned short int sequence) { return (sequence >> 14) == 3; } CLion's Clang-Tidy is giving me a "Use of a signed integer operand with a…
SakoDaemon
  • 973
  • 1
  • 6
  • 21
65
votes
2 answers

Inline way to disable clang-tidy checks

I'm trying to set up clang-tidy for a project. I'd like to be able to have clean output, and encourage the use of -fix mode where possible. However, there are individual cases where an exception is needed. Much as it is possible to use #pragma clang…
Rich L
  • 1,905
  • 2
  • 19
  • 30
56
votes
2 answers

How to install clang-tidy on macOS?

How do you install clang-tidy on macOS? It seems quite easy to install clang-format (using brew) on macOS, but it it seems much harder to install clang-tidy without install and building all of clang and building from source. Is there a better…
Michael Reneer
  • 2,271
  • 1
  • 16
  • 22
44
votes
3 answers

Ignore system headers in clang-tidy

tldr;> How do I hide warnings from system headers in clang-tidy? I have the following minimal example source file, which triggers a clang-tidy warning in the system headers: #include int main() { std::promise p; …
Heinzi
  • 5,793
  • 4
  • 40
  • 69
30
votes
7 answers

How to build the latest clang-tidy?

I've tried to build clang-tidy from sources but it complains about an undefined CMake command: CMake Error at clang-apply-replacements/CMakeLists.txt:5 (add_clang_library): Unknown CMake command "add_clang_library". CMake Warning (dev) in…
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
28
votes
5 answers

Is it possible to accelerate clang-tidy using ccache or similar?

Since employing ccache on our CI server, we find that the bottleneck in terms of build time is now our static analysis pass, that uses clang-tidy, among other tools. Does anyone know of a way to accelerate clang-tidy in a similar way to how ccache…
Tim Angus
  • 983
  • 11
  • 26
25
votes
3 answers

Clang-Tidy can't find my header files

new to clang and clang-tidy here. I have a project with this type of structure: project/ - build/ - cmake/ - component1/ - src/ - someFile.cpp - someFile2.cpp - someFile.hpp - someFile2.hpp - component2/ - etc... …
Maggie S.
  • 1,076
  • 4
  • 20
  • 30
24
votes
2 answers

Why clang-tidy suggests to add [[nodiscard]] everywhere?

I have a C++ project where clang-tidy is suggesting to add [[nodiscard]] everywhere. Is this a good practice ? The understanding I have is that [[nodiscard]] should be used only when ignoring the return value could be fatal for program. I have an…
21
votes
3 answers

clang-tidy - ignore third party headers code

I'm using CMake for my project and I wanted to introduce clang-tidy checks to the project. I'm using for this purpose CMAKE_CXX_CLANG_TIDY and .clang-tidy file for checks setup. I wanted to use warnings-as-errors to have reliable way in CI to check…
mpatro
  • 293
  • 2
  • 10
21
votes
2 answers

Ignore [clang-diagnostic-error] clang-tidy caused by 3rd party headers

I am using clang-tidy as a "linter" tool in development. I started to integrate 3rd party software into my code and when I include their header files using: -I/path/to/include tons of errors are generated, I haven't even #include the headers…
user2930353
  • 333
  • 1
  • 2
  • 6
21
votes
4 answers

clang-tidy: How to suppress warnings?

I recently started experimenting with the clang-tidy tool of llvm. Now I am trying to suppress false warnings from third party library code. For this I want to use the command line options -header-filter= or -line-filter= but so far…
Knitschi
  • 2,822
  • 3
  • 32
  • 51
19
votes
2 answers

What is the correct way of providing header-filter for clang-tidy in Cmake?

I have projects that sets Clang-tidy configuration as following set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=google-*,cppcoreguidelines-*;") However, I have noticed that it was checking all the files that are not even in the current repo…
Brandon Lee
  • 391
  • 1
  • 3
  • 6
19
votes
2 answers

Clang-tidy file: How to list the checks in multiple lines

Right now I have a .clang-tidy file that includes a large list of checks and they all go in one line like this: Checks: '-*,bugprone-*,-bugprone-narrowing-conversions, cert-*, -cert-err58-cpp,…
Darien Pardinas
  • 5,910
  • 1
  • 41
  • 48
19
votes
3 answers

Clang-Tidy `NOLINT` for multiple lines?

I'm working on a C++ project that has some large sections of code that are autogenerated, and I don't want to be linted. Is there something akin to the //NOLINT comment that can be applied to multiple lines? Like the following: //…
user3002473
  • 4,835
  • 8
  • 35
  • 61
19
votes
2 answers

Const-qualification of parameters in function declaration

I have the following function declaration in a header file: extern void flash(const char *message, const enum msg_type type); Basically, it takes two parameters and pushes a corresponding message into a global message queue. Since it doesn't need…
nalzok
  • 14,965
  • 21
  • 72
  • 139
1
2 3
26 27