Programming Search⌘K

C++ lints, page 2 of 3

The lint rules of C++, with what each one finds. This page has 553 cards.

Finds pthread_setcanceltype function calls where a thread's cancellation type is set to asynchronous. concurrency-thread-canceltype-asynchronous

Asynchronous cancellation type (PTHREAD_CANCEL_ASYNCHRONOUS) is generally unsafe, use type PTHREAD_CANCEL_DEFERRED instead which is the default. Even with deferred cancellation, a cancellation point in an asynchronous signal handler may still be acted upon and the effect is as if it was an asynchronous cancellation. The check is in the concurrency module of clang-tidy.

Code
concurrency-thread-canceltype-asynchronous

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

This check warns when structs or classes that are copyable or movable, and have const-qualified or reference (lvalue or rvalue) data members. cppcoreguidelines-avoid-const-or-ref-data-members

Having such members is rarely useful, and makes the class only copy-constructible but not copy-assignable. The check is in the cppcoreguidelines module of clang-tidy.

Code
cppcoreguidelines-avoid-const-or-ref-data-members

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Warns when using do-while loops. cppcoreguidelines-avoid-do-while

They are less readable than plain while loops, since the termination condition is at the end and the condition is not checked prior to the first iteration. This can lead to subtle bugs. The check is in the cppcoreguidelines module of clang-tidy.

Code
cppcoreguidelines-avoid-do-while

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

This check handles C-Style memory management using malloc(), realloc(), calloc() and free(). cppcoreguidelines-no-malloc

It warns about its use and tries to suggest the use of an appropriate RAII object. Furthermore, it can be configured to check against a user-specified list of functions that are used for memory management (e.g. posix_memalign()). The check is in the cppcoreguidelines module of clang-tidy.

Code
cppcoreguidelines-no-malloc

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

The check flags user-defined move constructors and assignment operators not marked with noexcept or marked with noexcept(expr) where expr evaluates to false (but is not a false literal itself). cppcoreguidelines-noexcept-move-operations

It is an alias of the check performance-noexcept-move-constructor, which does the same work. clang-tidy can fix the code that it finds.

Code
cppcoreguidelines-noexcept-move-operations

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Finds member initializations in the constructor body which can be converted into member initializers of the constructor instead. cppcoreguidelines-prefer-member-initializer

This not only improves the readability of the code but also positively affects its performance. Class-member assignments inside a control statement or following the first control statement are ignored. clang-tidy can fix the code that it finds. The check is in the cppcoreguidelines module of clang-tidy.

Code
cppcoreguidelines-prefer-member-initializer

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Finds calls to operator[] in STL containers and suggests replacing them with safe alternatives. cppcoreguidelines-pro-bounds-avoid-unchecked-container-access

Safe alternatives include STL at or GSL at functions, begin() or end() functions, range-for loops, std::span, or an appropriate function from <algorithms>. clang-tidy can fix the code that it finds. The check is in the cppcoreguidelines module of clang-tidy.

Code
cppcoreguidelines-pro-bounds-avoid-unchecked-container-access

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

This check flags all array subscript expressions on static arrays and std::arrays that either do not have a constant integer expression index or are out of bounds (for std::array). cppcoreguidelines-pro-bounds-constant-array-index

For out-of-bounds checking of static arrays, see the -Warray-bounds Clang diagnostic. clang-tidy can fix the code that it finds. The check is in the cppcoreguidelines module of clang-tidy.

Code
cppcoreguidelines-pro-bounds-constant-array-index

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

The check flags user-provided constructor definitions that do not initialize all fields that would be left in an undefined state by default construction, e.g. builtins, pointers and record types without user-provided default constructors containing at least one such type. cppcoreguidelines-pro-type-member-init

If these fields aren't initialized, the constructor will leave some of the memory in an undefined state. clang-tidy can fix the code that it finds. The check is in the cppcoreguidelines module of clang-tidy.

Code
cppcoreguidelines-pro-type-member-init

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Looks at conditionals and finds and replaces cases of cast<>, which will assert rather than return a null pointer, and dyn_cast<> where the return value is not captured. llvm-prefer-isa-or-dyn-cast-in-conditionals

Additionally, finds and replaces cases that match the pattern var && isa<X>(var), where var is evaluated twice. clang-tidy can fix the code that it finds. The check is in the llvm module of clang-tidy.

Code
llvm-prefer-isa-or-dyn-cast-in-conditionals

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Finds virtual function overrides with different visibility than the function in the base class. misc-override-with-different-visibility

This includes for example if a virtual function declared as private is overridden and declared as public in a subclass. The detected change is the modification of visibility resulting from keywords public, protected, private at overridden virtual functions. The check is in the misc module of clang-tidy.

Code
misc-override-with-different-visibility

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Warns for the usage of std::rand(). misc-predictable-rand

Pseudorandom number generators use mathematical algorithms to produce a sequence of numbers with good statistical properties, but the numbers produced are not genuinely random. The std::rand() function takes a seed (number), runs a mathematical operation on it and returns the result. The check is in the misc module of clang-tidy.

Code
misc-predictable-rand

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

Finds unused function parameters. misc-unused-parameters

Unused parameters may signify a bug in the code (e.g. when a different parameter is used instead). The suggested fixes either comment parameter name out or remove the parameter completely, if all callers of the function are in the same translation unit and can be updated. clang-tidy can fix the code that it finds. The check is in the misc module of clang-tidy.

Code
misc-unused-parameters

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

With move semantics added to the language and the standard library updated with move constructors added for many types it is now interesting to take an argument directly by value, instead of by const-reference, and then copy. modernize-pass-by-value

This check allows the compiler to take care of choosing the best way to construct the copy. clang-tidy can fix the code that it finds. The check is in the modernize module of clang-tidy.

Code
modernize-pass-by-value

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

This check replaces the uses of the deprecated class std::auto_ptr by std::unique_ptr (introduced in C++11). modernize-replace-auto-ptr

The transfer of ownership, done by the copy-constructor and the assignment operator, is changed to match std::unique_ptr usage by using explicit calls to std::move(). The check is deprecated. clang-tidy can fix the code that it finds. The check is in the modernize module of clang-tidy.

Code
modernize-replace-auto-ptr

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

This check converts constructors' member initializers into the new default member initializers in C++11. modernize-use-default-member-init

Other member initializers that match the default member initializer are removed. This can reduce repeated code or allow use of '= default'. clang-tidy can fix the code that it finds. The check is in the modernize module of clang-tidy.

Code
modernize-use-default-member-init

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.

The check flags insertions to an STL-style container done by calling the push_back, push, or push_front methods with an explicitly-constructed temporary of the container element type. modernize-use-emplace

In this case, the corresponding emplace equivalent methods result in less verbose and potentially more efficient code. Right now the check doesn't support insert. clang-tidy can fix the code that it finds. The check is in the modernize module of clang-tidy.

Code
modernize-use-emplace

Source: github.com, clang.llvm.org. JSON record. This entry is a card. Help write this page.