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
1
vote
0 answers
clang-tidy does not recognize standard libraries
I have a simple program that compiles and runs successfully, but I can't get clang-tidy to work.
My program:
#include
int main() {
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project(myProg…

narengi
- 1,345
- 3
- 17
- 38
1
vote
1 answer
Why clang-tidy readability-isolate-declaration not fixing code?
I tried to use readability-isolate-declaration check in clang-tidy, but nothing fixed. Example of code from test.cpp file:
void f() {
int a = 0, b = 1, c = 2;
}
What I've done:
clang-tidy -checks='readability-isolate-declaration' -fix…

a.wise
- 164
- 1
- 10
1
vote
2 answers
The 'cppcoreguidelines-interfaces-global-init' goes wrong just in a specific scenario
Given the cppcoreguidelines-interfaces-global-init, specifically "initializing non-local variable with non-const expression depending on uninitialized non-local variable", which is exemplified here, I have the following scenario:
My team consists…

anc
- 106
- 4
- 18
1
vote
0 answers
clang-tidy readability-non-const-parameter warning, why?
I ran into an clang-tidy warning I don't understand. I've created a minimum example:
test.cpp:
#include
#include
extern size_t get_data(float*const* buffers, size_t count);
size_t get_data_2_a(float* buffer1, float* buffer2)
{
…

Reinder
- 305
- 1
- 9
1
vote
1 answer
VS Code adding multiple repos
I'm using clang-tidy in VS Code, and I'm connecting to a remote machine via ssh. However, I have some include files that do not share the same area as my source file:
// Paths:
// /source/file/path/source.C
// /header/file/path/header.h
#include…

helloworld95
- 366
- 7
- 17
1
vote
0 answers
clang-tidy can't find the target's public headers
I have a cmake project on Windows which uses JOM as the generator and MSVC 19 as the compiler. Now I'm trying to add clang-tidy checks to some of my targets in this project. Here is part of my code to enable clang-tidy:
if ( CLANG_TIDY_EXE )
…

Alireza
- 800
- 1
- 7
- 21
1
vote
1 answer
Clang-Tidy: check number of lines in a function
Can you please help me with how to check CPP files in a project for functions exceeding 'n' number of lines using Clang-Tidy?

Pshah S
- 11
- 1
1
vote
0 answers
Clang AST find only syntax errors
I'm using Clang to create some internal static code analyzers. For one of the analyzers, we need to take a raw string and check if it has any syntax errors.
We shouldn't consider missing symbols, missing headers, invalid function calls etc. as…

OzB
- 2,140
- 1
- 22
- 38
1
vote
0 answers
clang-tidy ignoring preprocessor directives
I would like to make clang-tidy ignore preprocessor directives when checking through my code. I have code that looks like the following...
#ifdef NO_DEFINE
class wrongClass2 {
protected:
int m_M;
public:
wrongClass2(int M = 1): m_M(M) {};
int…

Interlooper
- 494
- 2
- 5
- 14
1
vote
0 answers
Correct clang-tidy UndefinedBinaryOperatorResult
I'm trying to get my code clang-tidy clean, and it's complaining that I'm using garbage values.
I have some data stored as words, and I want to use it byte by byte.
clang-tidy doesn't seem to identify the array size post c-style cast.
A minimal…

user100046
- 422
- 4
- 11
1
vote
1 answer
Why "The 'empty' method should be used to check for emptiness instead of 'size" by clang-tidy?
When performing the check:
std::string st = "hello";
bool is_empty = st.size() > 0;
I get the Clang-Tidy warning mentioned above.
Why is it better to use the empty() method instead?

joepol
- 744
- 6
- 22
1
vote
0 answers
Clang AST Matchers: is it possible filter based on count?
I was trying to write a simple clang-tidy checker that will check for constructor that is calling fopen() more than once. For that I was tying to match the constructor with more than one fopen() calls. My indention is to find potential memory leak…

vrnithinkumar
- 1,273
- 1
- 11
- 29
1
vote
1 answer
clang-tidy fails bugprone check
I'm experimenting with clang-tidy using the following file:
#include
int main(int argc, char **argv)
{
int i=2; int j=1;
if (argc = 5) { return 2; }
while (i

OrenIshShalom
- 5,974
- 9
- 37
- 87
1
vote
0 answers
Showing multiple ranges in Clang DiagnosticBuilder
In a clang-tidy check I am writing, I want to show multiple ranges. And there is
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
ArrayRef Ranges)
which seems to be…

Alexey Romanov
- 167,066
- 35
- 309
- 487
1
vote
2 answers
Avoid pointer arithmetic, fix clang tidy error
Is it possible to solve the following issue clang tidy is throwing out.
error: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic,-warnings-as-errors]
The project I am using is a mix of C/C++ and no changes can be made on…

tester123
- 399
- 1
- 3
- 10