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
3
votes
2 answers
Handling large volume of boost unit test related warnings with clang-tidy
I'm in the process of setting up a project. I have skeleton tests in place using boost unit-test. Unfortunately a large number of warnings are spawned from the macro expansions. Is there a way to disable these, without have to specify individual…

Jibbity jobby
- 1,255
- 2
- 12
- 26
2
votes
2 answers
How to display "Problems" only for the code I changed/added in Visual Studio Code?
After 3 years on VS, I decided to try Visual Code with clangd for a bit.
I work for a big company with huge legacy code and technical debt so I often have to work with some old code and not so modern C++ and more often than not I must read a lot of…

Krustibat
- 81
- 5
2
votes
2 answers
clang-tidy warning: an exception may be thrown in function
Having this code (mName is a member of type std::string)
//.h
[[nodiscard]] auto name() const noexcept -> std::string;
and
// .cpp
[[nodiscard]] auto NodeData::name() const noexcept -> std::string {
return mName;
}
clang-tidy is giving the…

Ionut Cosmin Mihai
- 189
- 1
- 12
2
votes
1 answer
clang-tidy errors with file not found when using CMake interface targets and compilation database
Overview
I am trying to run clang-tidy against my c++ codebase, which is built using cmake.
I am generating a compilation database as part of the build and passing this via the -p flag to clang-tidy - however, clang-tidy complains with error:…

Matthew Fennell
- 47
- 1
- 8
2
votes
0 answers
Why is clang-tidy in clangd so much faster than (run-)clang-tidy itself?
I have a fairly large project with lots & large headers that are included.
Running clang-tidy on a single source file takes 10+ minutes.
In contrast to that clang-tidy findings in clangd show up almost immediately.
I expect clangd to be faster due…

pJunger
- 41
- 6
2
votes
0 answers
Why clang++ fails to compile code proposed by clang-tidy
I have a very simple code with reverse-iteration loop:
#include
#include
int main()
{
auto v = std::vector();
v.push_back(1);
v.push_back(2);
v.push_back(3);
for (auto r = v.rbegin(); r !=…

Krzysiek Karbowiak
- 1,655
- 1
- 9
- 17
2
votes
0 answers
RapidJSON and clang-tidy and thread_local
I am working on a C++17-project which I am compiling under Linux with GCC 9. However, I EDIT the project under Windows 11 in QT Creator 10 using clangd/clangTidy(16.0.0).
Now, when it comes to code that uses thread_local, I get errors in clang-tidy,…

SoulfreezerXP
- 459
- 1
- 5
- 19
2
votes
1 answer
clang-tidy: Warn when a container holds a particular class
Using LLVM-15's clang-tidy linter, I'd like to enforce the use of a typedef. Instances of
std::unordered_set
used as a variable declaration, function return, or in a using/typedef, should instead be written…

Richard
- 56,349
- 34
- 180
- 251
2
votes
1 answer
How to enable and disable a clang-tidy rule in Visual Studio?
Visual Studio has a feature that lets me enable clang-tidy checks. In the property pages, I went to Configuration properties, Code analysis, General and set "Enable Clang-Tidy" to "Yes":
In the Clang-Tidy section, Visual Studio allows me to enter…

Thomas Weller
- 55,411
- 20
- 125
- 222
2
votes
1 answer
Clang tidy doesn't work properly for static member variable
I am running clang-tidy for my project. Here are the relevant naming options from my .clang-tidy file:
- key: readability-identifier-naming.ClassMemberCase # e.g., int myClassMember_
value: camelBack
- key: …

Danny
- 354
- 3
- 13
2
votes
1 answer
modern c++ with clang-tidy causes opposite warnings
this is my 2nd question and i tried to find a matching request and hope i didn't overlooked it this time.
I'm trying to understand modern C++ a little bit more in depth. So a hint was teaching it yourself by using clang and i'm trying it atm but i'm…

mirrowwinger
- 25
- 4
2
votes
0 answers
ClangTidy + CMake - ignore third party headers from Conan
I am trying to use ClangTidy on some working source code but I cannot get it to ignore / bypass lib{fmt} and see lots of noise such as:
~/.conan/data/fmt/9.1.0///package/2c09c8f84c016041549fcee94e4caae5d89424b6/
include/fmt/core.h:2955:15: warning:…

mark
- 7,381
- 5
- 36
- 61
2
votes
1 answer
Thread safe initialization of string from getenv (environment variable)
I have a project with tight level of clang-tidy static analysis.
In order to check some consistencies in the environment I am probing the value of a few environment variables.
int main() {
char const* ompi_size_cstr =…

alfC
- 14,261
- 4
- 67
- 118
2
votes
0 answers
"no matching function call for async in clion"
might be needing your wisdom here! I'm using std::async() as following:
std::vector> futures; // store the return value of std::async, necessary step to make async work
std::mutex nef_mutex; // for thread-safety
void…

F. Z
- 21
- 2
2
votes
0 answers
How to configure naming conventions with clang-format?
My team is interested in adding a tool to enforce style guidelines for C++. Two of the best options we have researched are clang-tidy and clang-format.
clang-format appears to meet nearly all of our needs, however one thing I have been unable to…

ryansantaana
- 21
- 4