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
5
votes
1 answer

Wrong clang-tidy warning about static global lambda variables?

Provided the following code, in the global scope, clang-tidy gives no warning: auto test = []{}; However, when doing the following, it does: #include auto test = []{ std::tuple t{1, 2, 3}; }; :3:6: warning: initialization of…
asu
  • 1,875
  • 17
  • 27
5
votes
2 answers

clang-tidy inserts multiple 'override' specifiers when fixing

I have this cmake project that I would like to modernize using clang-tidy. In order not to have too many things happening at once, I only activated the modernize-use-override option. However, when I apply this: $> run-clang-tidy -header-filter='.*'…
ThorOdinsson
  • 252
  • 1
  • 2
  • 7
5
votes
2 answers

Using NOLINT to suppress clang-tidy. How can I suppress the suppression?

I have code like the following int do_thing( int arg1, int arg2, int arg3 ) { // NOLINT : don't care that arg2 and arg3 aren't used return arg1; } the NOLINT comment suppresses a clang-tidy warning normally. However, how can I 'reenable'…
Michael Mullin
  • 73
  • 1
  • 2
  • 6
5
votes
1 answer

Use clang-tidy on CUDA source files

Several static analysis tools designed for C/C++ exist, but they are not particularly useful for testing CUDA sources. Since clang version 6 is able to compile CUDA, I wanted to check what are my options with using clang-tidy, which does not seem to…
Johny
  • 1,947
  • 13
  • 23
5
votes
2 answers

Silencing clang-tidy

I have a build which uses clang-tidy through cmake: set_target_properties(project PROPERTIES ... CXX_CLANG_TIDY "/usr/bin/clang-tidy" "-checks=modernize-*,readability-*,performance-*" "-fix" ) While building it I…
Mac
  • 3,397
  • 3
  • 33
  • 58
4
votes
1 answer

How can I get clang-tidy to not complain about passing kind-of-lightweight types by value?

CLion (2023.1.2) is running clang-tidy v17 on a project of mine. It's complaining about me passing an std::experimental::optional (from C++14) by value instead of by reference. That seems egregious to me... how can I increase the "object weight…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
4
votes
1 answer

clang-tidy complains on std::string in structs

struct Thing { std::string something; }; Clang-tidy complains: warning: an exception may be thrown in function 'Thing' which should not throw exceptions [bugprone-exception-escape] I know about the…
Alex O
  • 1,429
  • 2
  • 13
  • 20
4
votes
2 answers

'Clang-Tidy: Do not implicitly decay an array into a pointer' when using std::forward and const char*

I do not understand why Clang-Tidy produces the error Clang-Tidy: Do not implicitly decay an array into a pointer in the following example: struct Foo { explicit Foo(std::string _identifier) : identifier(std::move(_identifier)) {} std::string…
jawa
  • 125
  • 5
4
votes
3 answers

Prevent clang tidy to report warnings on Boost Test headers

Note December 2022: it seems that this problem is solved in clang-tidy 14. Just by experimentation I can reproduce the problem with clang-tidy 11, 12 and 13 but not with 14. I have a Cmake project that uses Boost.UnitTest for testing. When I do…
alfC
  • 14,261
  • 4
  • 67
  • 118
4
votes
1 answer

clang-tidy with precompiled headers and cmake does not work

I have a simple setup where CMake produces the following compile command: cd /workspaces/cmake-general/tests/project/build/examples/hello-world && /usr/local/bin/cmake -E __run_co_compile --iwyu=/usr/local/bin/include-what-you-use…
Gabriel
  • 8,990
  • 6
  • 57
  • 101
4
votes
1 answer

How to avoid clang-tidy warnings about uninitialized variables

I am looking for the best way to avoid cppcoreguidelines-init-variables warnings with clang-tidy. std::istringstream in(line); float x, y, z, rotx, roty, rotz; in >> x >> y >> z >> rotx >> roty >> rotz; -> variable 'x' is not initialized,…
PJ127
  • 986
  • 13
  • 23
4
votes
2 answers

What are the risks of variables with protected visibility

I'm trying to implement a state pattern as explained in this example. I've gotten to code similar as below. class State { public: virtual void enter() {}; virtual void update() = 0; virtual void exit() {}; virtual void…
4
votes
3 answers

Using #pragma to remove clang warnings based on clang check

I want to remove/ignore a clang warning for a block of code and found multiple examples of how to use pragamas for this. For example if the warning is unused-variable you can disable it by using: #pragma clang diagnostic push #pragma clang…
JakobVinkas
  • 1,003
  • 7
  • 23
4
votes
3 answers

How to dump CLion's default clang-tidy configuration?

I want to use the default configuration of enabled/disabled checks from CLion (with some small changes) and I want to enforce it when building my application. Enforcing clang-tidy works perfectly by using the cmake directive for clang-tidy, for…
ph_0
  • 617
  • 8
  • 27
4
votes
2 answers

clang-tidy parsing error at spaceship operator

Using clang++-11 with libstdc++-11 and clang-tidy-11, I run into failures when linting the code with clang-tidy - namely parsing error when dealing with the well-known sleeper std::this_thread::sleep_for(std::chrono::seconds(1));. clang-tidy-11…
Leśny Rumcajs
  • 2,259
  • 2
  • 17
  • 33