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.
Questions tagged [clang-tidy]
404 questions
8
votes
1 answer
Is Clang-Tidy's warning about failure to initialize all fields of an anonymous union a false positive?
I have code like the following in a C++ project:
struct Foo {
union {
double d = 1.0;
char c;
};
};
When I run this through Clang-Tidy, it warns me that constructor does not initialize the field c. However, when I compile the code, I do…
user2269707
8
votes
2 answers
clang-tidy can't locate stdlib headers
Today I've built clang-tidy from sources, I've built it using clang++. After it has been built I've created a symlink to the executable like this:
ln -s /path/to/build/bin/clang-tidy /usr/local/bin/clang-tidy
Then I've tried to use clang-tidy with…

mezo
- 423
- 1
- 7
- 19
8
votes
3 answers
cmake + clang_tidy - disable checking in directory
I have large project using CMake. I want to add clang_tidy-8 support with following code:
set(BORG_CLANG_TIDY OFF CACHE STRING "If enabled, clang-tidy will be used. If set to 'fix', fixes will be done on source")
set_property(CACHE BORG_CLANG_TIDY…

MateuszL
- 2,751
- 25
- 38
8
votes
1 answer
clang-tidy readability-identifier-naming module does not seem to properly handle class attributes and class methods
I would like to use clang-tidy 'readability-identifier-naming' module to clean my code, but I failed to use it properly on a short example with class attribute and method.
I used the following .clang-tidy file:
Checks:…

devel484
- 165
- 1
- 2
- 7
8
votes
3 answers
What is proper LLVM header guard style?
In clang tidy, the check [llvm-header-guard] looks for LLVM style header guards, but I can't find any examples of proper LLVM header guard style, specifically the structure of the name given to the define, the coding standards pages does not mention…

A-n-t-h-o-n-y
- 410
- 6
- 14
8
votes
2 answers
How can I enable clang-tidy's "modernize" checks?
I just installed ClangOnWin,and I'm trying to get clang-tidy's "modernize" checks to work. Unfortunately, clang-tidy doesn't seem to know about them: clang-tidy -list-checks foo.cpp -- | grep modernize produces no output.
The "modernize" checks are…

KnowItAllWannabe
- 12,972
- 8
- 50
- 91
7
votes
2 answers
Disable or enable warnings for cppcheck using a configuration file
With clang-tidy static analyzer I can keep a file (.clang-tidy) in the root of the project with the warnings I want to activate or deactivate.
clang-tidy will look for this file (as far I know) and use the options defined there. This saves me from…

alfC
- 14,261
- 4
- 67
- 118
7
votes
1 answer
clang-tidy emits warning when compiling with c++20 enabled
I recently updated my project and its CI pipelines to use C++20 features. When I changed the compiler settings to use C++20, clang-tidy started to emit the following warning (I treat them as errors) for all my checked files:
error: invalid case…

wychmaster
- 712
- 2
- 8
- 23
7
votes
0 answers
clang-tidy: Ignore specific folder from clang-tidy analysis
I have the following directory structure
├── .clang-format
├── .clang-tidy
├── external
├── scripts
└── source
For my clang tidy execution I want to only include headers from the source folder and exclude ones from external. The following setting…

user2020
- 217
- 2
- 12
7
votes
2 answers
Using clang-tidy with a header only CMake project
I am working on a header only library and would like to use clang-tidy to make sure I am following the "C++ Core Guidelines" https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
No matter what I try I can't seem to get clang-tidy to work on…

tjwrona1992
- 8,614
- 8
- 35
- 98
7
votes
1 answer
No `-line-filter` equivalent in clang-tidy config?
I want to configure my -line-filter= arguments in the .clang-tidy file instead of in a cmake source file where the command is generated. Adding a LineFilter key to the file only gets me a "unknown key" error. Is this really not supported via the…

renefritze
- 2,167
- 14
- 25
7
votes
0 answers
clang-tidy vs structured bindings
The clang-tidy packaged in ubuntu 20.04 (10.0.0) seems to be choking on a fairly simple block of code that involves structured bindings and move operations:
#include
#include
struct T {
~T() {
if(ptr != nullptr) { //…
user4442671
7
votes
2 answers
Disable clang-tidy warning for a specific macro
I have a macro which instantiates a global variable. And thus clang-tidy will correctly issue an "Initialization of ... with static storage duration may throw an exception which cannot be caught".
Can I disable this warning on a per-macro basis?…

Johan W
- 71
- 1
- 4
7
votes
0 answers
How to run clang-tidy and clazy on a qmake Qt project from cmd?
I have a few Windows projects based on qmake, and these are built daily on Jenkins. Jenkins is running on a Windows machine, and my projects build fine using a "Windows batch Command", which is pretty much the same as running a good old batch (.bat)…

FourtyTwo
- 1,616
- 2
- 15
- 43
7
votes
3 answers
CLang-Tidy warning that rand() has limited randomness
toZero = rand() % N;
This line of code is giving me Clang-Tidy: rand() has limited randomness. Why is this warning coming up? How can I fix it?
user9310391