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
11
votes
1 answer
Does clang-tidy make clang-check redundant?
Both of these tools seem to share some common goals and while the documentation of clang-tidy is quite explicit about its capabilities, clang-check's is a bit sparse.
It would be nice if I could run only one of these tools while having the same…

lbonn
- 2,499
- 22
- 32
10
votes
1 answer
Is it possible to ignore a header with clang-tidy
I want to include a header from an external project, but clang-tidy is quite unhappy about it and produces a huge list of warnings. To workaround this, I am trying to disable all diagnostics coming from this header.
I tried:
// NOLINTBEGIN
//…

ivaigult
- 6,198
- 5
- 38
- 66
10
votes
1 answer
Warning for overflow in std::accumulate
Is there any way to get a warning for std::accumulate when the type of the init arg doesn't match the contained type you are accumulating over? e.g. in this example we shouldn't accumulate a 32 bit value when iterating over a vector of 64 bit ints.…

Rick Buczynski
- 181
- 4
10
votes
0 answers
What is a loop with an ID-dependent backward branch?
I am trying to understand this clang-tidy warning: altera-id-dependent-backward-branch that seems to be triggered by this loop.
for(; first != current; ++first)
The example I have is this code, that looks almost exactly as a perfectly…

alfC
- 14,261
- 4
- 67
- 118
10
votes
2 answers
Is there a way to enforce using "this->" for class members/methods in clang-format/clang-tidy?
I was searching everywhere, but I probably used the wrong terms. I haven't found an option for this.
The only thing I found is this unanswered question (which is however a bit broader): CPP lint: Can you enforce use of this for class variables? .

Martin Pecka
- 2,953
- 1
- 31
- 40
10
votes
1 answer
Template class + delegating constructor = fields not initialized? (clang-tidy)
I'm running clang-tidy 8.0 and I am getting the warning:
constructor does not initialize these fields:
when using a delegating constructor on a templated class. I want to know if this is a false positive I should suppress, or if indeed my code is…

user1011113
- 1,114
- 8
- 27
9
votes
2 answers
clang-tidy: How to suppress C++ warnings in C header file?
I've got a .h file that is included by both C and C++ source files. Its contents is wrapped in
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif
Yet, when I include it in a .cpp file, clang-tidy issues C++-specific messages,…

Wolfram Rösler
- 302
- 1
- 12
9
votes
1 answer
Is it code smell to use std::move on all class value-copies "just in case"?
I have a function that gets a "Config" struct, which at the moment is simply a struct that contains an array
class ShmConfig {
public:
std::int64_t shellShmSize[ShellId_Count];
};
And I pass it on to another function in the function with…

Johannes Schaub - litb
- 496,577
- 130
- 894
- 1,212
9
votes
1 answer
error: unable to handle compilation, expected exactly one compiler job in '' [clang-diagnostic-error]
Build fails without much helpful information after I've added this into my CmakeLists.txt to enable clang-tidy checks:
if(ENABLE_CLANG_TIDY)
find_program(CLANGTIDY clang-tidy)
if(CLANGTIDY)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
…

Maksym Rudenko
- 706
- 5
- 16
9
votes
0 answers
NDK issues with Studio 3.5.2 on Ubuntu
I am new to NDK. Just upgraded to Android Studio 3.5.2, installed LLDB 3.1.4508709, NDK (Side by side) 21.0.6113669, CMake 3.6.4111459 (BTW, the interface is terrible) on Ubuntu 16.04.
Created a new Native C++ project from template.
Every time I…

Alex B
- 347
- 1
- 3
- 9
9
votes
1 answer
Why does clang-tidy say vsnprintf has an uninitialized va_list argument?
In the following function, I initialize args, use them in the call to va_start, and then call va_end.
The code looks right to me, but clang-tidy gives a warning:
tmp2.c:7:11: error: Function 'vsnprintf' is called with an uninitialized va_list…

jyn
- 463
- 4
- 16
9
votes
1 answer
Clang-tidy header-filter regex: Makefile -> .clang-tidy
I'm attempting to move the hardcoded config option of clang-tidy from our Makefile to a .clang-tidy YAML file. As of now, we call run-clang-tidy-6.0.py as such:
# Run clang-tidy. The header filter includes files in the foo and bar/baz directories
#…

Brandon Schaefer
- 451
- 1
- 4
- 12
9
votes
1 answer
Is there a way to avoid this warning from clang-tidy (fuchsia-default-arguments) while initializing a string?
Consider this piece of code:
#include
int main () {
std::string str = "not default";
std::cout << str << std::endl;
return 0;
}
Running clang-tidy -checks=* string.cpp gives the following:
7800 warnings…

urmish
- 127
- 1
- 6
9
votes
2 answers
clang-tidy cmake exclude file from check
I have a dependency as source in my project that I have no control over.
I'm using cmake's clang-tidy integration to analyze my code, and this dependency is firing A LOT of warnings. Is there a way to tell cmake not to run clang-tidy on specific…

Niverton
- 163
- 1
- 2
- 6
8
votes
1 answer
Detect use-after-move for global variables
After some effort, I convinced both the clang compiler and clang-tidy (static analyzer) to warn of a use-after-move situation. (see https://stackoverflow.com/a/74250567/225186)
int main(int, char**) {
a_class a;
auto b = std::move(a);
…

alfC
- 14,261
- 4
- 67
- 118