488 questions
Advice
0
votes
1
replies
12
views
clang-tidy, after a custom replacement I wrote, how to re-parse the text
I'm currently writing a clang-tidy check for a particular monadic replacement for c++. Think of it something like, for particular types and notations, f(x) becomes x(f) - this, of course, requires an ...
Tooling
1
vote
9
replies
133
views
need to update 8000+ C files -- clang-tidy?
I have inherited a project with over 8000 C source files from 26 years ago, so they have all kinds of old cruft that modern compilers (and best practices) won't put up with (old-style function ...
Tooling
0
votes
5
replies
96
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
66
views
Clang-Tidy cannot find included files
I'm using a CMake project in combination with Conan package manager.
Building my project works fine, but I'm currently struggling with Clang-tidy.
I'm having this very simple file fmt_dummy.cpp:
#...
-3
votes
1
answer
78
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
2
answers
220
views
Why is initializing a struct field with a default value considered a 'magic-number' by clang-tidy? [closed]
Consider the following example:
struct DefaultSettings {
std::string tcpIpAddress = "127.0.0.1";
uint16_t tcpPort = 1993; // Marked as magic number!
}
clang-tidy (with readability-magic-...
1
vote
1
answer
347
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(...
2
votes
1
answer
97
views
Clang-Tidy warnings for static coroutine methods initial_suspend and final_suspend
Can (and maybe should) my coroutine promise class MyCoroutine::Promise have static or non-static initial_suspend and final_suspend methods?
static std::suspend_always initial_suspend() noexcept
{
...
0
votes
0
answers
103
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
0
answers
88
views
clang-tidy for Arduino code, how to suppress a warning about Arduino.h
Running clang-tidy v19 on Ubuntu 24.04
$ clang-tidy-19 --version
Ubuntu LLVM version 19.1.7
The code is for Arduino, so there is:
#include "Arduino.h"
That generates 3 clang-tidy warnings:
...
1
vote
1
answer
99
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/...
4
votes
1
answer
101
views
Clang-tidy bugprone-use-after-move with perfect forwarding
clang-tidy reports the following piece of code as bugprone-use-after-move
template <typename F, typename Tuple, size_t... I>
auto transform_tuple_impl(F&& f, Tuple&& tuple, std::...
2
votes
1
answer
166
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 ...
1
vote
1
answer
221
views
Suspicious comparison of 'sizeof(expr)' to a constant
I did a static_assert to make sure that a valid type was used. I don't know if I just should have checked if the type is void, or whether any type can have size zero (I think it can with [[...
0
votes
0
answers
86
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-*,
-...
4
votes
2
answers
235
views
cppcoreguidelines-virtual-class-destructor ... complains when Base has default protected destructor
We are using clang-tidy to do static analysis, and we've enabled cpp-core-guidelines.
As per previous advice (by one of the authors of cpp-core-guidelines), we have a abstract base class with a ...
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 ...
-1
votes
2
answers
84
views
clang-tidy uses FunctionCase for class methods
I have a .clang-tidy file which includes
CheckOptions:
- { key: readability-identifier-naming.ClassMethodCase, value: CamelCase }
- { key: readability-identifier-naming.FunctionCase, value: ...
2
votes
1
answer
235
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,...
2
votes
0
answers
348
views
How do I avoid both modernize-deprecated-headers and misc-include-cleaner warnings?
I'm trying to remove all clang-tidy warnings in my C++ project. But I get alternating modernize-deprecated-headers and misc-include-cleaner warnings.
For example:
I use open_memstream in a file, so I ...
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 ...
2
votes
0
answers
127
views
How to run Visual Studio's Code Analysis on the command line exactly like in the IDE?
I have a VS solution with multiple projects. The code is written in C. I am using Visual Studio 17.12.4 Enterprise. When I run the Code Analysis within VS, the analysis is successful on all ...
3
votes
2
answers
104
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
#...
2
votes
1
answer
483
views
clang-tidy won't enforce "m_" prefix only on class members (public members too)
I'm using clang-tidy version 17 to enforce the usage of "m_" prefix on class members (regardless of public/private/protected) but not on structs. Only adding readability-identifier-naming....
0
votes
1
answer
93
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
124
views
Clang-tidy check: how to identify the scope of variables
I am writing a test that checks whether a variable already exists in the same scope. There should be a warning if there is already a similar variable in the same scope.
For example, an error should be ...
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<...
2
votes
1
answer
72
views
Matching sugared QualType of a template parameter in a varDecl()
Background
The built-in C++ types don't have defined sizes (just a minimum size), so we
require all integer types to use explicitly-defined typedefs so the size is the
same across all platforms, ...
1
vote
1
answer
90
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 ...
0
votes
1
answer
1k
views
Visual Studio Code Clangd only use clang-tidy for project. Problems with external include
I want to use clang-tidy in VsCode to establish a consistent coding style.
The project does not use Cmake and I am currently not feeding compiler-options to clang-tidy. I am running into problems ...
5
votes
2
answers
487
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
2
answers
231
views
Clang-Tidy: Uninitialized record type
While trying to create a socket connection to my port I encounter the following warning from CLion
Clang-Tidy: Uninitialized record type: 'server_address'
Here is my code:
#include <iostream>
#...
0
votes
0
answers
402
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-...
1
vote
1
answer
480
views
How to fix "multi level implicit pointer conversion" warning in clang-tidy?
I have some legacy code that reads like this:
bool has_attribute(int kvidx) const {
void* v = nullptr;
int flag = 0;
MPI_Comm_get_attr(impl_, kvidx, &v, &flag);
return flag != ...
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
91
views
How to get the access specifier for a clang::CXXMethodDecl?
I would like to know whether my C++ method is public, protected or private when writing a clang-tidy check. That seems to be a very simple task. But I could not figure out how to solve this, as clang::...
1
vote
1
answer
890
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 ...
1
vote
1
answer
341
views
Identifying type definitions in Macros with clang-tidy
I'm writing (my first) clang-tidy check. It should detect when macros define types, like:
#define MY_INT int
#define MY_STRING std::string
class MyClass {}
#define MY_CLASS MyClass
#define ...
2
votes
1
answer
76
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 ...
1
vote
0
answers
211
views
How to enable clang-tidy to inspect header files and related interfaces
Currently we are integrating clang-tidy into our project and we found that it has troubles when we introduce interfaces to classes (in multiple files).
Consider following code
//driver_interface.hpp
...
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
2
answers
186
views
Clang-tidy tries to analyze an STM32 assembly file located in compile_commands.json
I have an STM32 project which is compiled using CMake and generates a compile_commands.json
STM32CubeMX generates an assembly file (i.e. startup_stm32f103xb.s) and adds it to the compilation database.
...
0
votes
0
answers
72
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 ...
1
vote
0
answers
334
views
Qt Clang-Tidy pipeline
I'm trying to create an azure pipeline to run clang-tidy to check my Qt code.
The file:
trigger:
- development
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: Lint
displayName: 'Lint C++ code with ...
2
votes
2
answers
344
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
480
views
How to skip checking third-party dependencies when using clang-tidy?
I'm using clang-tidy in my C++ project, and I'm encountering errors related to third-party dependencies, specifically Abseil (absl). I want to skip checking these dependencies.
jiawei@DESKTOP-AEQS7B5:~...
0
votes
1
answer
86
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
0
answers
144
views
How to stop clang-tidy running on sources from FetchContent?
I have this CMakeLists.txt:
# ...
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}")
macro(target_enable_clang_tidy TARGET)
...
1
vote
1
answer
173
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
0
answers
53
views
clang-tidy fails to report prefer-member-initializer correctly
I have this class constructor
struct CosseratRodPrecomputation {
CosseratRodPrecomputation(Scalar L0,
const Vec3 &xA_,
const Vec3 &...