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
2 answers

clang-tidy: Exclude specific dir from analysis

I'm using clang-tidy in a medium-size project with the following three folders: srcA srcB external I'm trying to exclude external folder from the analysis, but with no luck. The command I'm using is: clang-tidy $SRC -p build/…
tsarquis88
  • 453
  • 1
  • 6
  • 14
5
votes
1 answer

Clang Tidy config format

At the moment I am using the Clang Format utility in my project. In order to share its settings in my team, I put the .clang-format configuration file in the root of the project folder, and now IDE automatically loads it when working with the…
Timur Yalymov
  • 249
  • 2
  • 8
5
votes
1 answer

Does clang-tidy make scan-build redundant?

I have a project that currently uses both scan-build and clang-tidy (enabled via CMake). If I enable clang-analyzer-* in my set of clang-tidy checks, is the usage of scan-build redundant? For reference, there is a similar question asked here about…
tbre
  • 51
  • 2
5
votes
1 answer

"Potential memory leak" with std::function

Consider this example: #include #include #include #include using closure_type = std::function; using closure_vec = std::vector; class callbacks { static closure_type…
ivaigult
  • 6,198
  • 5
  • 38
  • 66
5
votes
1 answer

how to use clang tidy in CMake

I would like to use CMake and clang-tidy in my project, however I see that build times are quite a bit higher when I use this in all the main cmake file: set(CMAKE_CXX_CLANG_TIDY clang-tidy-11; -format-style='file'; …
Frank
  • 2,446
  • 7
  • 33
  • 67
5
votes
0 answers

clang-tidy: getting postfix operator++ right

I have a custom forward iterator type. It declares (among other stuff) this: Iter& operator++(); Iter operator++(int); clang-tidy complains about cert-dcl21-cpp (Clang-Tidy: Overloaded 'operator++' returns a non-constant object instead of a…
5
votes
0 answers

Clang-Tidy is ambiguous: What should operator++(int) return?

So, I've been working on a Vector implementation for an assignment and noticed some strange Clang-Tidy suggestions while implementing the iterators. The iterator must have an iterator& operator++() and an iterator operator++(int) overload, per the…
Raphael Tarita
  • 770
  • 1
  • 6
  • 31
5
votes
1 answer

Why is this dangling-gsl warning invoked?

I am analyzing a codebase with clang-tidy and see a warning I do not understand. The warning is invoked by the following lines of code: void fun(const QString& bar) { const char* c_format = bar.toStdString().c_str(); …
fabian
  • 1,413
  • 1
  • 13
  • 24
5
votes
1 answer

Can that function parameter really be pointer-to-const?

In the following C program, functions f, g, and h are essentially identical, however clang-tidy says that parameter p can be pointer-to-const in g and h (but not in f). My understanding is that p can't be pointer-to-const in any of them. Is that a…
Wolfram Rösler
  • 302
  • 1
  • 12
5
votes
2 answers

Understanding "'const' at top level, which may reduce code readability without improving const correctness"

Please consider the code below, in particular, observing that get_length returns const size_t. #include const size_t get_length(void) { return 123; } void foo(void) { size_t length = get_length(); length++; …
user14222280
5
votes
1 answer

What is the meaning of the 'AnalyzeTemporaryDtors' option in clang-tidy?

The clang-tidy --dump-config command produces something like this: --- Checks: 'clang-diagnostic-*,clang-analyzer-*' WarningsAsErrors: '' HeaderFilterRegex: '' AnalyzeTemporaryDtors: false FormatStyle: none User: …
5
votes
1 answer

How can I tell clang-tidy to check for pragma once instead of llvm-style header guards?

I would like to use clan-tidy. The program should check if I do have header guards, which is why I set the flag llvm-header-guard. Unfortunately this checks if the header guards are llvm-style, which I don't want. I want to use #pragma once. Does…
User12547645
  • 6,955
  • 3
  • 38
  • 69
5
votes
1 answer

Clang AST matcher for variables compared to different variable types

I am new to clang-tidy and the following is practice so I can move to more complex matchers and tools. Lets say we have typedef int my_type; void foo() { int x = 0;//this should be identified as need to be fixed my_type z = 0; …
warz
  • 73
  • 4
5
votes
2 answers

clang-tidy with CMake and an embedded target

The goal here to help people catch some bugs on their embedded systems when developing with C++. As part of this I'm trying to get clang-tidy to work for small embedded targets. I'm trying setup CMake to do the following: Run clang tidy on build;…
David Ledger
  • 2,033
  • 1
  • 12
  • 27
5
votes
2 answers

Is the "used after it was moved [bugprone-use-after-move]" warning a real problem here?

I'm adapting the idea of the deffered ptr Herb Sutter talked about in cppcon 2016, to be able to manage external resources represented by an id in a safer way. Therefore I created a non copy able and only movable class holding the id the resource…
t.niese
  • 39,256
  • 9
  • 74
  • 101