486 questions
Tooling
0
votes
5
replies
94
views
A Clang tool to add extra line of code whenever a #define is true
I want to develop a tool that helps in transforming a code like this:
#ifdef MYLIB_ENABLE_DEPRECATED_CODE
... some deprecated code ...
#endif
into:
#ifdef MYLIB_ENABLE_DEPRECATED_CODE
...
-3
votes
1
answer
73
views
QT Creator 17.0.1: Clang-Tidy interface looks nothing like documentation
I'm trying QT Creator's Clang-Tidy interface. The documentation suggests I'll see something usable and aesthetically appealing, like this:
The reality is a vomit of command-line output, like this:
...
1
vote
1
answer
328
views
Clangd: call to consteval function 'fmt::basic_format_string<...>' is not a constant expression, but MSVC compiles it
I'm using spdlog with fmt::format_string to log messages, and I also want to capture the call location using std::source_location. My goal is to have a simple logging function like this:
Logger::Error(...
0
votes
0
answers
98
views
Using Clang Tidy in CMake with an MSVC project (or, using Clang Tidy in CMake as a separate target)
Not exactly sure how to title this nicely.
I've got a large CMake project that is targeting the MSVC compiler with Ninja build files. I'd like to integrate Clang-Tidy to analyze our code but am ...
1
vote
1
answer
94
views
clang-tidy warning Is a directory [clang-diagnostic-error]
Running clang-tidy v19 on Ubuntu 24.04
$ clang-tidy-19 --version
Ubuntu LLVM version 19.1.7
Generated a compile_commands.json: has 2 entries in it:
[
{
"arguments": [
"/usr/...
2
votes
1
answer
165
views
Should we still always std::forward a universal reference argument even if unnecessary?
Consider the following code:
#include <string>
auto f1(auto&& v) {
return v;
}
auto f2(auto&& v) {
return std::forward<decltype(v)>(v);
}
int main() {
return ...
0
votes
0
answers
85
views
clang-tidy - does not always report uninitialized members
Here is my .clang-tidy:
Checks: >
clang-analyzer-*,
bugprone-*,
cppcoreguidelines-*,
misc-*,
performance-*,
portability-*,
cert-*,
-fuchsia-*,
-llvm-header-guard,
-hicpp-*,
-...
1
vote
1
answer
63
views
clang libtooling: how to get expansion EndLoc of function-like macros?
I am writing a module of clang-tidy, which finds declarations of variables with the necessary condition and perform FixItHint:CreateReplacement() for them.
I found VarDecl, which defined via a strange ...
2
votes
1
answer
225
views
Can I get clang-tidy to warn about the use of indirectly-included standard library constructs
Consider the following program:
#include <array>
int main() {
throw std::logic_error("hi");
}
With some C++ compilers (or rather, standard libraries) - this compiles. For example,...
0
votes
0
answers
55
views
Clang-Tidy in Trunk Runs but Doesn't Show Issues in VS Code Sidebar
I'm using Trunk in VS Code to run clang-tidy as a linter for my C++ project. When I run:
trunk check
I can see clang-tidy running in the output, and it does find issues:
...
...
...
10:2 medium ...
3
votes
2
answers
102
views
Avoid security.ArrayBound warning when using container_of
I have code using container_of macros to get parent structure pointer from inner structure pointer. However, it triggers the clang-tidy security.ArrayBound warning.
For instance the following code
#...
0
votes
1
answer
91
views
How can I get clang-tidy not to complain about lack of apostrophe in an identifier?
My IDE is running clang-tidy (v20) on my C++ code. I have an enum where one of the identifiers is isnt_owning. And - clang tidy complains about the typo. <sarcasm>Thanks a bunch! I'll go right ...
1
vote
0
answers
81
views
Should an rvalue parameter always get moved? [duplicate]
I've got the below piece of code that causes a warning with clang-tidy.
void process(const std::vector<uint8_t> &buffer)
{
// ... process the message ...
}
void process(std::vector<...
1
vote
1
answer
88
views
Clang-Tidy fails to analyze QT project that uses Pybind11 due to reserved 'slots' keyword
I would like to use Clang-Tidy to lint my Cmake QT project, which I develop in QTCreator. It is a C++ project that uses Pybind11 to interface with Python code.
Unfortunately, running Clang-tidy from ...
5
votes
2
answers
474
views
Warning "bugprone-exception-escape" when captured object throws in copy constructor
When I have a C++ lambda that captures an object by value, and that object can throw an exception in its copy constructor, clang-tidy will show a warning:
warning: an exception may be thrown in ...
0
votes
0
answers
389
views
Applying clang-tidy's readability-identifier-naming fix corrects only the header files
I'm trying to use clang-tidy with readability-identifier-naming fix to change the naming style in a small project, i.e. I want to rename multiple symbols across multiple files. For some reason clang-...
3
votes
1
answer
107
views
How to convert a copy initialization into a direct list initialization in clang-tidy check?
I would like to write a clang-tidy check that finds field declarations with copy initialization (ICIS_CopyInit) and can change them into direct list initializations (ICIS_ListInit).
There is a way to ...
1
vote
1
answer
874
views
Using `misc-include-cleaner` with <windows.h>
I would like to use the misc-include-cleaner check from clang-tidy in my codebase, but unfortunately, the <windows.h> header used throughout WinAPI conflicts with IWYU philosophy.
Technically, I ...
2
votes
1
answer
75
views
How to get the source location for a ref qualifier when writing clang-tidy checks and fixes?
I would like to write a clang-tidy check that adds an lvalue ref qualifier to certain C++ methods. I have managed to detect the methods to fix, but I have troubles finding the right source location to ...
0
votes
1
answer
86
views
Compiler or Clang tidy warning on methods that directly access the file system
my C++ code has calls to classes such as std::ifstream to open a file for reading or std::filesystem methods that iterate over directories or check if a file exists - I intend to abstract these away ...
0
votes
0
answers
71
views
vscode static c analyzer gives error when analyzing any file that includes windows.h
When ever I include windows.h when writing C, the analyzer would give me a thousand errors , I could just simply ignore them but the problem is that it won't detect any problem in the code I write
I ...
2
votes
2
answers
334
views
Linter check for reference removal in auto type
I wanted to know if there is any compiler option or clang-tidy checks for this situation:
#include<iostream>
#include <ostream>
int glob = 12;
int& test(int d){
std::cout <<...
0
votes
1
answer
85
views
How should I define and initialize a non-global namespace member variable?
In my Memory.hpp file, I have a namespace boolean named isMHinit:
namespace Memory
{
static bool isMHInit = false;
DWORD HookFunction(LPVOID pTarget, LPVOID pDetour, LPVOID pTrampoline, BOOL ...
1
vote
1
answer
171
views
Clang AST Matchers: how to find function with specific name?
I try to match all expressions that call to std::sort, so I wrote code like this
Unfortunately, the check function of this class is not called.
I also tried AddMatcher code like this:
but it still ...
0
votes
1
answer
1k
views
Why is the compile_commands.json file not generating when I build a project using CMake?
I am trying to create a CI/CD pipeline in gitlab that builds my project in the first stage and uses clang-tidy to run static analysis in the second stage. I soon realized that clang-tidy uses the ...