Questions tagged [clang-tidy]

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.

404 questions
7
votes
1 answer

How to load function with dlsym() without reinterpret_cast?

I'm trying to use clang-tidy to enforce the C++ Core Guidelines. While it does have a lot of valid points, there is one thing I cannot really work around: dlsym returns a void* which I need to turn into a proper function pointer somehow. To do that…
Calmarius
  • 18,570
  • 18
  • 110
  • 157
7
votes
2 answers

How can I specify additional arguments for use with CMAKE_CXX_CLANG_TIDY variable

I'm trying to use make use of clang-tidy integration with cmake and I'd like to pass the -check argument. I've tried adding -DCMAKE_CXX_CLANG_TIDY="/usr/local/opt/llvm38/bin/clang-tidy-3.8;-checks=*" when invoking cmake, but my makefile commands…
Mike Ellery
  • 2,054
  • 3
  • 21
  • 30
6
votes
2 answers

Clang-Tidy slow with dependencies

I am using clang-tidy to lint my code base, but the entire process is very slow. Is there a way to completely ignore header files and not only suppress the warnings? As you can see with this example, a ton of warnings are coming from my project…
6
votes
1 answer

clang-tidy: `Loop variable is copied but only used as const reference; consider making it a const reference` - does it really matter?

I'm working on code that clang-tidy is flagging all over the place with Loop variable is copied but only used as const reference; consider making it a const reference Current code: for (auto foo : collection) { ... } What clang-tidy suggests I…
Edward Falk
  • 9,991
  • 11
  • 77
  • 112
6
votes
1 answer

Using clang-tidy to analize embedded GCC project

I'm trying to use clang-tidy to parse my project, compiled by arm-none-eabi-g++. Unfortunately, clang-tidy is not able to find compiler headers, even when given the include path to them. My compile_commands.json is [ { "directory":…
MLapaj
  • 371
  • 3
  • 11
6
votes
1 answer

How to fix llvmlibc-restrict-system-libc-headers check in Clang Tidy?

I do not understand the llvmlibc-restrict-system-libc-headers check in Clang Tidy (link). I include C libraries in C++ code like this: #include What should I change to fix this Clang Tidy check? Should it be fixed at all?
Wouter Beek
  • 3,307
  • 16
  • 29
6
votes
1 answer

How to specify compilation database for clang-tidy

I am struggling with running clang-tidy for my project. I am trying to run clang-tidy for my project for send data to Codacy. I am doing it like this: clang-tidy $PWD -header-filter=.*,-checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* |…
Vento
  • 155
  • 2
  • 8
6
votes
1 answer

clang-tidy suggest I remove const references, why?

I ran clang-tidy (the "modernize" modules) on a project tree that I have been trying to keep reasonably up to date with C++17. Almost everything it corrected was unsurprising to me, except for one thing: It changed all of these types of…
cypheratheist
  • 163
  • 2
  • 11
6
votes
1 answer

clang-tidy's bugprone-exception-escape behaves weirdly with MSVC STL

I'm using clang-tidy 10 on a project and it's behaving weirdly on Windows with the MSVC STL. A minimal example is the following: #include #include int main() { try { throw std::runtime_error {"Boom!"}; } catch…
6
votes
2 answers

Where to find list of available options for Clang-tidy "readability-identifier-naming" checker?

Use case I want to configure readability-identifier-naming checker for clang-tidy running on my codebase. Background The checker in clang-tidy can be provided with CheckOptions, such like: clang-tidy -checks='-*,readability-identifier-naming' \…
Bartek
  • 71
  • 1
  • 3
6
votes
2 answers

clang-tidy -fix does not apply any changes

I'm running clang-tidy with the following command: run-clang-tidy.py -checks="-*,cppcoreguidelines-*,hicpps-*" -header-filter=".*" -fix" (or clang-tidy -checks="-*,cppcoreguidelines-*,hicpps-*" -header-filter=".*" -fix" also works) This returns a…
Sharky
  • 323
  • 1
  • 3
  • 11
6
votes
2 answers

Setting a sub-option to clang-tidy

I am using clang-tidy from cmdline clang-tidy readability-implicit-bool-conversion ... ". This clang-tidy option has the sub-option AllowPointerConditions, in order for clang-tidy to allow me to use if (!p) whithot…
Taw
  • 479
  • 3
  • 15
6
votes
1 answer

Clang-tidy warning for static std::stringstream

I have the following MCVE: #include struct A { static std::stringstream s; }; std::stringstream A::s; int main() {} When I run clang-tidy 6.0.1 on this code I get the following warning: static_sstream.cpp:7:22: warning:…
Nikola Benes
  • 2,372
  • 1
  • 20
  • 33
6
votes
1 answer

Do Clang vs Clang tidy detect the same warnings and errors ?

As far as I know the Clan-tidy can do these checks https://clang.llvm.org/extra/clang-tidy/checks/list.html over and above default checks set (clang-analyser) and Clang can also detect errors and…
Rigó Zoltán
  • 61
  • 1
  • 2
6
votes
4 answers

How-to integrate clang-tidy with CMake (_CLANG_TIDY) and MSVC?

How can one pass a clang flag, e.g. -fms-compatibility-version with the _CLANG_TIDY CMake property? On the CLI this is easy: clang-tidy main.cpp -- -fms-compatibility-version=19.10 But with CMake this does not work as…
Florian Wolters
  • 3,820
  • 5
  • 35
  • 55