Questions tagged [clang-tidy]

1

votes
1

answer
27

Views

Clang-tidy incorrect rounding

Documentation for clang-tidy [bugprone-incorrect-roundings] check says: The number 0.499999975 (smallest representable float number below 0.5) rounds to 1.0 As far as I can detect the smallest float number below 0.5 is 0.4999999702, not a 0.499999975. But despite of this, both numbers give me 0 valu...
αλεχολυτ
1

votes
1

answer
56

Views

Clang format output errors

Is it possible to have clang-format issue output as warnings saying what to fix similar to clang tidy. I would prefer to use clang-format due to the ease of setting up styles.
Hassan Syed
1

votes
0

answer
95

Views

Using Clang-Tidy to gate check in for Visual Studio

I'm trying to use Clang-Tidy to automatically gate check-ins/builds on Visual Studios. I know that in cmake there is a variable 'CMAKE_CXX_CLANG_TIDY', but setting it to my tidy executable with the proper checks doesn't seem to do anything when building the project. Also, I am unable to easily gener...
Raj Shah
1

votes
1

answer
82

Views

How do I pass GslHeader argument to clang-tidy while using -fix option?

I couldn't find sample code for a clang-tidy command line for fixing the following error: [[email protected] fizzbuzz]$ clang-tidy fizzbuzz2.cpp -checks=cppcoreguidelines-pro-bounds-constant-array-index 5 warnings generated. fizzbuzz2.cpp:21:18: warning: do not use array subscript when the index i...
Urmish Shah
1

votes
1

answer
181

Views

Use clang-tidy to output issues with formatting

Is it possible to set up clang-tidy to output issues it has found with the formatting of the source code as defined by the .clang-format file. Basically, telling you what kind of changes clang-format would do if it ran on the file. Something along the lines of: Line 23: improper indentation, 4 spac...
polaris6933
1

votes
0

answer
70

Views

clang-tidy incorrectly replaces template parameter in typedef

I ran clang-tidy over a selection of my codebase, and noticed a few typedefs including template parameters being incorrectly replaced with concrete types. I managed to replicate at least one of this issues with this example file, test.cc: template struct Test { typedef T test_1; typedef T test_2; t...
John Ilacqua
1

votes
0

answer
38

Views

Ignore inline assembly related diagnostic errors in clang-tidy

I am trying to use clang-tidy (version 6.0.0) to run some static analysis on a code base that is supposed to run on a custom control processor. It works quite well except for some diagnostic errors that it generates whenever it encounters inline assembly. For example: error: unknown register name '...
Vijay
1

votes
0

answer
91

Views
1

votes
0

answer
49

Views

How to use clang-tidy with -Wdocumentation flag

I want to use my custom check and clang-diagnostics (-Wdocumentation) at the same time, but i don't want to have compile_commands.json at all. I tried this: clang-tidy.exe -checks='mycheckmodule-*' -fix-errors %FILE% -- -Wdocumentation but it doesn't work. Any help would be highly appreciated
Alexander Kuznetsov
1

votes
1

answer
174

Views

android studio 3.3 clang-tidy

Yesterday, Google updated Android Studio to version 3.3 and there it was possible to use a static analyzer for libraries supporting C ++. So, how exactly to use it? I include in: Preferences->Editor->Inspections->General->Clang-tidy (Use IDE setting ) but nothing else. If you try through the termin...
SergeyLoskutnikov
1

votes
0

answer
63

Views

Run and automatically apply clang-tidy refactoring to entire project folder

Is there a way to run and automatically refactor the entire project source code by applying all the clang-tidy quick-fixes?
Francesco Borzi
1

votes
1

answer
39

Views

How make clang-tidy apply FixItHints sequentially, one after another?

I'm writing clang-tidy check that will move comment in right place like that: Before: /// comment 1 void func(); void func2(); /// comment 2 void func3(); /// comment 3 After: /// comment 1 void func(); /// comment 2 void func2(); /// comment 3 void func3(); I'm trying to remove /// comment 3 and th...
1

votes
1

answer
312

Views

Handling large volume of boost unit test related warnings with clang-tidy

I'm in the process of setting up a project. I have skeleton tests in place using boost unit-test. Unfortunately a large number of warnings are spawned from the macro expansions. Is there a way to disable these, without have to specify individual line numbers?. This occurs even when I have a // NOLIN...
Peter Bingham
1

votes
1

answer
377

Views

clang-tidy: Analyze file with multiple errors

Is it possible to analyze a C/C++ file in clang-tidy, while ignoring its syntax/compilation errors? I have a very big file that has several compilation errors, but I still want to analyze it with clang-tidy. I'm getting the following error message: 20 warnings and 20 errors generated. Error while p...
Train
1

votes
1

answer
51

Views

clang-tidy check to require parentheses around compound expressions

I would like to catch cases like this: if(a == 2 && b == 3) and convert them to: if((a == 2) && (b == 3)) I didn't see anything that sounded like this here - is there a way to enable this?
David Doria
1

votes
1

answer
95

Views

clang tidy pro type member init resharper

I've got some code parsing json like so: QJsonParseError errors; auto doc = QJsonDocument::fromJson(myJson.toUtf8(), &errors); Resharper's clang tidy suggestions flags that QJsonParseError errors is an 'uninitialized record type' The suggested fix is to zero initialize the variable via {} for C++11...
CaptRespect
1

votes
1

answer
762

Views

macOS homebrew llvm clang tidy some checks are missing

I have installed LLVM via brew on macOS with the below mentioned command: brew install --with-toolchain [email protected] I would like to use clang-tidy but some checks are missing, for example misc-string-compare. What could be the problem?
hsgmltb
1

votes
1

answer
54

Views

what are all the legal key for .clang-tidy

Is there a place that documents .clang-tidy file? all I could find is this: $ clang-tidy -dump-config --- Checks: '-*,some-check' WarningsAsErrors: '' HeaderFilterRegex: '' FormatStyle: none User: user CheckOptions: - key: some-check.SomeOption value: 's...
Ezra
1

votes
1

answer
68

Views

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 warnings. https://clang.llvm.org/extra/clang-tidy/checks/readability-implicit-bool-co...
Taw
1

votes
1

answer
86

Views

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 lot of errors. It also says applying fixes... in the...
Sharky
1

votes
1

answer
0

Views

I would like to install clang-tidy as a linter for cpp on CentOS 7 but cannot locate a package

I was able to install both llvm and clang via the epel repository. However, they do not include the clang-tidy binary. I have been searching the llvm website but they do not have any packages available for CentOS 7. The ius repository doesn't have clang-tidy either. I would like to double check...
Tristan
1

votes
1

answer
0

Views

Clang-Tidy `NOLINT` for multiple lines?

I'm working on a C++ project that has some large sections of code that are autogenerated, and I don't want to be linted. Is there something akin to the //NOLINT comment that can be applied to multiple lines? Like the following: // BEGINNOLINT bad-code; // ENDNOLINT All I could find online was a sugg...
user3002473
1

votes
1

answer
142

Views

How to strictly target C++98 in CLion

For some reason I cannot configure CLion to only use C++98 for my project I keep getting clang-tidy for c++11 instead of c++98 (How do I set it to C++98) I do not get any red lines or compiler errors when I use syntax for C++ versions greater than C++98 (How do I enable strict enforcement of C++98)...
Tim
1

votes
1

answer
3.6k

Views

Clang-Tidy can't find my header files

new to clang and clang-tidy here. I have a project with this type of structure: project/ - build/ - cmake/ - component1/ - src/ - someFile.cpp - someFile2.cpp - someFile.hpp - someFile2.hpp - component2/ - etc... - When I use clang-tidy to go through all the files in project/component1/ with this co...
Maggie S.
1

votes
1

answer
62

Views

clang analyzer can't detect null dereferencing

I'm playing with clang static analyzer ( clang++ --analyze or clang-tidy, win64, v6.0.1). Clang analyzer can detect a null dereference in this case: class SomeClass { public: int a = 5; }; int GetA( SomeClass* someClass ) { return someClass->a; } int main() { SomeClass* someClass = nullptr; return G...
benoitj
2

votes
3

answer
2.5k

Views

What is proper LLVM header guard style?

In clang tidy, the check [llvm-header-guard] looks for LLVM style header guards, but I can't find any examples of proper LLVM header guard style, specifically the structure of the name given to the define, the coding standards pages does not mention anything.
A-n-t-h-o-n-y
12

votes
1

answer
2.8k

Views

Ignore system headers in clang-tidy

tldr;> How do I hide warnings from system headers in clang-tidy? I have the following minimal example source file, which triggers a clang-tidy warning in the system headers: #include int main() { std::promise p; p.set_value(3); } Calling it with libstdc++ 7.0.1 using clang-tidy 4.0.0 on Ubuntu 17.0...
Heinzi
2

votes
1

answer
108

Views

C++98, but clang-tidy says use nullptr?

I am using Clion and my project is set to C++98, but clang-tidy has suggestions to use nullptr instead of NULL. Is there a clang-tidy setting somewhere in the IDE or is it something else?
delimiter
12

votes
2

answer
1.4k

Views

“Use of a signed integer operand with a binary bitwise operator” - when using unsigned short

In the following C snippet that checks if the first two bits of a 16-bit sequence are set: bool is_pointer(unsigned short int sequence) { return (sequence >> 14) == 3; } CLion's Clang-Tidy is giving me a 'Use of a signed integer operand with a binary bitwise operator' warning, and I can't understand...
SakoDaemon
6

votes
1

answer
485

Views

How-to integrate clang-tidy with CMake (<LANG>_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 expected: -DCMAKE_CXX_CLANG_TIDY='clang-tidy;-checks=-*,readability-*;--;-fms-comp...
Florian Wolters
4

votes
1

answer
1.5k

Views

Clion Unintialized record type: player

I have started learning C++ a few weeks ago. I am seeing now classes and all the stuff, and I was wondering about object instantiation. In this code: class Player { public: int x, y; int speed; }; int main () { Player player {}; return 0; } I get a warning from the IDE if I don't put braces in Playe...
vrodriguez
6

votes
3

answer
5.3k

Views

clang-tidy: How to suppress warnings?

I recently started experimenting with the clang-tidy tool of llvm. Now I am trying to suppress false warnings from third party library code. For this I want to use the command line options -header-filter= or -line-filter= but so far without success. So for people with limited time I will put the que...
Knitschi
4

votes
2

answer
1.7k

Views

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 end-up looking like: /usr/local/Cellar/cmake/3.6.2/bin...
Mike Ellery
7

votes
2

answer
2.5k

Views

How to build the latest clang-tidy?

I've tried to build clang-tidy from sources but it complains about an undefined CMake command: CMake Error at clang-apply-replacements/CMakeLists.txt:5 (add_clang_library): Unknown CMake command 'add_clang_library'. CMake Warning (dev) in CMakeLists.txt: No cmake_minimum_required command is present....
ruipacheco
3

votes
2

answer
360

Views

Evaluate return value from ninja clang-tidy using CMake in batch

I am using CMake 3.6 to generate a ninja 1.6.0 configuration, compile and statically analyze my code using clang-tidy (LLVM version 3.9.1): # file copied from http://www.labri.fr/perso/fleury/posts/programming/using-clang-tidy-and-clang-format.html # Additional targets to perform clang-format/clang-...
Mihai Galos
3

votes
1

answer
70

Views

Which clang-tidy checks provide automated fixes?

I'd like to find out which of the clang-tidy checks are possible to run with the -fix option, i.e. automatically generate fixed code. I know all the modernize-* checks can do this and some other checks can too (like google-readability-casting) but nowhere did I find a complete list. Is there a list...
pablo285
3

votes
1

answer
403

Views

Is there a way to avoid this warning from clang-tidy (fuchsia-default-arguments) while initializing a string?

Consider this piece of code: #include int main () { std::string str = 'not default'; std::cout
Urmish Shah
6

votes
1

answer
357

Views

Does clang-tidy make clang-check redundant?

Both of these tools seem to share some common goals and while the documentation of clang-tidy is quite explicit about its capabilities, clang-check's is a bit sparse. It would be nice if I could run only one of these tools while having the same checks in place. Obviously, clang-tidy has some feature...
lbonn
2

votes
2

answer
339

Views

Const-qualiftion of parameters in function declaration

I have the following function declaration in a header file: extern void flash(const char *message, const enum msg_type type); Basically, it takes two parameters and push a corresponding message into a global message queue. Since it doesn't need to modify the parameters, I const-qualified them. Howev...
nalzok
5

votes
1

answer
103

Views

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: initializing non-local variable with non-const expression depending on uninitia...
Nikola Benes

View additional questions