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
0
votes
0 answers
How to prevent incorrect clang-tidy:readability-redundant-string-cstr detection?
Here is the typical (pseudo) code I wish to handle in clang-tidy (eg also here) for conveying an optionally null terminated fixed size buffer to std::string:
% cat str.cc
#include
#include
// read byte buffer from file, at most…

malat
- 12,152
- 13
- 89
- 158
0
votes
1 answer
Different clang-tidy-17 behavior locally and in CI
The problem
I'm running clang-tidy on Ubuntu jammy locally and in GitHub Actions. The problem is that I get different behavior in these environments for the following code, where MyType is trivially-copyable:
void MyClass::setField(MyType value) {
…

Eyjafl
- 1,046
- 6
- 14
0
votes
2 answers
Why is clang-tidy produces "narrowing conversion" for this C99 program?
Why does the 2nd and 3rd assignments in f2 produces this and the first doesn't?
Clang-Tidy: Narrowing conversion from 'int' to signed type 'char' is implementation-defined
AFAIK, according to C language specification the type of the ternary operator…

traveh
- 2,700
- 3
- 27
- 44
0
votes
0 answers
How can I tell CMake to make clang-tidy use a different system header path?
The question is about a CMake project that uses Clang as a compiler.
I am building on a Mac, using the Apple Clang that comes with XCode. Since clang-tidy is not included, I installed LLVM from homebrew just for clang-tidy, while still using the…

Alex O
- 1,429
- 2
- 13
- 20
0
votes
1 answer
How to specify "max-loop" option for Clang Tidy?
I'm trying this, but doesn't work:
$ clang-tidy --config="analyzer-max-loop: 10" a.cpp --
:1:1: error: unknown key 'analyzer-max-loop'
analyzer-max-loop: 10
^~~~~~~~~~~~~~~~~
Error: invalid configuration specified.
Invalid…

yegor256
- 102,010
- 123
- 446
- 597
0
votes
0 answers
How to check naming Convention for static global variables in C using clang-tidy?
I'm trying to set up clang-tidy to check the right naming conventions for global variables. I'd like it to be able to distinguish between global static and global non-static variables.
int globalNonStatic = 1; /* Should be camelBack */
static int…

Bavo Van Achte
- 11
- 4
0
votes
0 answers
Is clang-tidy backward compatible?
Let's assume we compose .clang-tidy yaml file on version X of clang-tidy. Should we synchronize this X version across all team members and CI? If someone update his clang-tidy version to more abvanced, will he get different diagnostics with the same…

Aleksandr Serov
- 31
- 2
0
votes
1 answer
How can I tell VS Code Cpptools' clang-tidy support to use the compile_commands.json generated with CMake?
I have an existing cross-compilation build that uses Yocto and CMake. I've added:
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
to CMakeLists.txt to generate compile_commands.json as part of my build. How can I tell VSCode's clang-tidy support to use this…

parsley72
- 8,449
- 8
- 65
- 98
0
votes
1 answer
How to supress clang-tidy warnings from an upstream library in cmake
I am using CMake as my build system generator. I want to use spdlog and clang-tidy. I add spdlog to my project_packages like this:
find_package("spdlog" REQUIRED)
target_link_libraries("project_packages" INTERFACE "spdlog::spdlog")
I set up…

Brandon
- 456
- 2
- 6
- 19
0
votes
0 answers
Bug in QTCreator 9.01 with C++ using clang-tidy and fixits
In an experiment with QtCreator 9.01 (windows 10), I encounter a bug when I unleash clang-tidy with the "performance-unnecessary-value-param"-check on a larger C++ code base ( > 700 files). It finds about 300 cases and I want to fix all at once, so…

SoulfreezerXP
- 459
- 1
- 5
- 19
0
votes
1 answer
How can I get a single cppcheck / clang-tidy result report file for all modules in my project?
in my project I have a multiple modules and I want to integrate cppcheck or clang-tidy with cmake. The problem is that in case of integration mentioned tools in cmake and perform static analysis I get report only for last checked module. Is there a…

emes9
- 1
0
votes
0 answers
How to get warning about NullDereference with clang analyzer if the a _Nullable argument is used in the function
I would like to detect NullDereference error by adding a _Nullable to my function.
I wrote my_function(); It is a function will lead to NullDerenference error if the ptr is NULL. To give a hint to the clang analyzer, I use _Nullable ptr as my…

prgbenz
- 1,129
- 4
- 13
- 27
0
votes
1 answer
argument unused during compilation: '-mcpu=cortex-m7' when using arm-none-eabi-g++ with clang-tidy
I am using CMake to run clang-tidy while compiling my embedded target.
if(CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
endif()
CMake sets the correct driver mode automatically:
--tidy="clang-tidy;--extra-arg-before=--driver-mode=g++"
But…

elhe
- 122
- 10
0
votes
0 answers
Clang-tidy change check options for clang-analyzer-optin.cplusplus.UninitializedObject
I am trying to change the Pedantic option in clang-analyzer-optin.cplusplus.UninitializedObject by create a .clang-tidy file
optin-cplusplus-uninitializedobject
here is the YAML version of .clang-tidy config-file:
Checks: >
…

Am_A
- 1
- 1
0
votes
1 answer
clang-tidy default checks (unknown origin)
My clang-tidy seems to have some hardcoded options I cannot get rid of, without any .clang-file (as seen in --explain-config below):
clang-tidy --checks=-* --dump-config
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*'
WarningsAsErrors:…

Liviu
- 1,859
- 2
- 22
- 48