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
How to delete a line with clang-tidy?
I'm creating a clang-tidy checker to replace a function with another function. The replaced function is relying on a using namespace ..; declaration. As part of my clang-tidy checker I also want to remove that declaration.
#include…

ByteNudger
- 1,545
- 5
- 29
- 37
1
vote
0 answers
Matching multiple arguments to a particular function individually with Clang AST matcher
I'm trying to match unnecessary calls to c_str() when calling functions that are happy to take the std::string directly so that I can remove the unnecessary call so that I can write a clang-tidy check to automatically turn statements…

Mike Crowe
- 642
- 6
- 18
1
vote
1 answer
How to use clang AST matcher usingDirectiveDecl to find using namespace directive with specific name?
I'm trying to prototype a clang-tidy matcher with clang-query to find using namespace directive with a certain name like using namespace ns1::ns2;.
With clang-query I tried these variants but none is matching anything:
clang-query> match…

ByteNudger
- 1,545
- 5
- 29
- 37
1
vote
0 answers
fixing clang warning in declaring vector
I have declared a vector container like this
const std::vector Levels = {0x01U, 0x02U, 0x07U, 0x11U};
The clang gives me these warnings,
test.cpp:6:1: warning: static objects are disallowed; if possible, use a constexpr constructor…

ganeshredcobra
- 1,881
- 3
- 28
- 44
1
vote
1 answer
ignore system headers when applying clang-tidy on macOS project
I’ve started using clang-tidy on my cmake based project that runs on macOS platform.
Unfortunately, this option isn’t supported on Xcode project generation but only in Makefile.
So when I compiled on the first time, one of the error related to a…

Zohar81
- 4,554
- 5
- 29
- 82
1
vote
1 answer
c++ clang-tidy gives errors related to llvm-libc
I have been having trouble getting clang-tidy to work on my local computer. My code is filled with these three errors:
error: declaration must be declared within the '__llvm_libc' namespace…

Neil Wiborg
- 23
- 6
1
vote
1 answer
Generate compile_commands.json from msbuild via command line -- no cmake
I'm looking for a way to integrate clang-tidy into a CI workflow, but the build system being used is MSBuild with dependencies managed by vcpkg in manisfest mode.
Is there some advanced command line that I can pass MSBuild (or some other tool that…

C. Nihelton
- 106
- 9
1
vote
0 answers
clang-tidy displays errors in system headers
I'm trying to run clang-tidy on my IAR project, but I would like to ignore system header files. I tried the solutions provided here but they didn't work (read on for the results). Here's my project structure:
Proj
----Src
----Inc
SysHdrs
And this…

Alaa M.
- 4,961
- 10
- 54
- 95
1
vote
1 answer
Is the AST, abstract syntax tree, defined by the language or by the frontend?
In the last few weeks I have been experimenting with ASTs and Clang, in particular clang-tidy.
Clang offers some classes and way to interact with the ASTs, but what I don't understand is if the clang::VarDecl I am using so often is something named…

Fede2424
- 67
- 6
1
vote
0 answers
Why doesn't Clang-tidy detect a narrowing conversion from float to uint8_t in a function call?
We just caught a tiny bug that I would have expected Clang-Tidy to catch for us, so please let me know if this isn't expected behavior. We have the following piece of code
float value = 3.4f; //
result = function(&a, b, c, value);
Where value…

Imara
- 37
- 3
1
vote
1 answer
lambda iso std::bind for member function
I have the following class on which I run clang-tidy.
template
class Bar
{
public:
template
Bar(void (THandlerObj::*pCmdHandler)(const Foo&),
THandlerObj* pCmdHandlerContext)
…

Frank
- 2,446
- 7
- 33
- 67
1
vote
0 answers
False-positive `clang-analyzer-core.uninitialized.*` or hidden threats of using `std::valarray`?
I use clang-tidy static code analyzer
$ clang-tidy --version
LLVM (http://llvm.org/):
LLVM version 11.0.1
Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: skylake
Given a code
#include
std::valarray f()
{
…

Charlie
- 826
- 1
- 11
- 27
1
vote
1 answer
clang-tidy bugprone-unused-return-value: how to check all functions?
I have clang-tidy checking for unused return values with bugprone-unused-return-value check. Unfortunately it only checks return values from list of functions specified with CheckedFunctions parameter. I would like to check usage of return value…

jviita
- 114
- 2
- 11
1
vote
0 answers
clang tidy incorrectly parsing doxygen comment
In code that uses doxygen comments, we have this:
/// @see @ref Foo::Bar()
This generates a "See also" section in doxygen with an explicit link to the Foo::Bar() class/method.
But with clang-tidy, this comment generates an error:
example.h:70:12:…

Stéphane
- 19,459
- 24
- 95
- 136
1
vote
1 answer
clang tidy bug when fix readability-braces-around-statements.ShortStatementLines
when i use clang-tidy to add braces in short statement there is a bug.
The code
else
_pContext(blabla);
is replaced by
else
{_}
pContext(blabla);
do you know how to fixe it ?
my .clang-tidy fil is like that
Checks: …

Tom Penard
- 141
- 8