Programming Search⌘K

C++ lints, page 3 of 3

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

This check replaces deprecated dynamic exception specifications with the appropriate noexcept specification (introduced in C++11). modernize-use-noexcept

By default this check will replace throw() with noexcept, and throw(<exception>[,...]) or throw(...) with noexcept(false). 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-use-noexcept

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

Converts calls to absl::StrFormat, or other functions via configuration options, to C++20's std::format, or another function via a configuration option, modifying the format string appropriately and removing now-unnecessary calls to std::string::c_str() and std::string::data(). modernize-use-std-format

clang-tidy can fix the code that it finds. The check is in the modernize module of clang-tidy.

Code
modernize-use-std-format

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

Finds constants and function calls to math functions that can be replaced with C++20's mathematical constants from the numbers header and offers fix-it hints. modernize-use-std-numbers

Does not match the use of variables with that value, and instead, offers a replacement for the definition of those variables. Function calls that match the pattern of how the constant is calculated are matched and replaced with the std::numbers constant. clang-tidy can fix the code that it finds. The check is in the modernize module of clang-tidy.

Code
modernize-use-std-numbers

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

Converts calls to printf, fprintf, absl::PrintF and absl::FPrintf to equivalent calls to C++23's std::print or std::println as appropriate, modifying the format string appropriately. modernize-use-std-print

The replaced and replacement functions can be customised by configuration options. Each argument that is the result of a call to std::string::c_str() and std::string::data() will have that now-unnecessary call removed in a similar manner to the. clang-tidy can fix the code that it finds. The check is in the modernize module of clang-tidy.

Code
modernize-use-std-print

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

Rewrites function and lambda signatures to use a trailing return type (introduced in C++11). modernize-use-trailing-return-type

This transformation is purely stylistic. The return type before the function name is replaced by auto and inserted after the function parameter list (and qualifiers). clang-tidy can fix the code that it finds. The check is in the modernize module of clang-tidy.

Code
modernize-use-trailing-return-type

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

This check verifies if a buffer passed to an MPI (Message Passing Interface) function is sufficiently dereferenced. mpi-buffer-deref

Buffers should be passed as a single pointer or array. As MPI function signatures specify void * for their buffer types, insufficiently dereferenced buffers can be passed, like for example as double pointers or multidimensional arrays, without a compiler warning emitted. clang-tidy can fix the code that it finds. The check is in the mpi module of clang-tidy.

Code
mpi-buffer-deref

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

This check verifies if buffer type and MPI (Message Passing Interface) datatype pairs match for used MPI functions. mpi-type-mismatch

All MPI datatypes defined by the MPI standard (3.1) are verified by this check. User defined typedefs, custom MPI datatypes and null pointer constants are skipped, in the course of verification. clang-tidy can fix the code that it finds. The check is in the mpi module of clang-tidy.

Code
mpi-type-mismatch

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

Finds calls to NSInvocation methods under ARC that don't have proper argument object lifetimes. objc-nsinvocation-argument-lifetime

When passing Objective-C objects as parameters to the NSInvocation methods getArgument:atIndex: and getReturnValue:, the values are copied by value into the argument pointer, which leads to incorrect releasing behavior if the object pointers are not declared __unsafe_unretained. clang-tidy can fix the code that it finds. The check is in the objc module of clang-tidy.

Code
objc-nsinvocation-argument-lifetime

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

Check for integer to enumeration casts that would produce a value with no corresponding enumerator. optin.core.EnumCastOutOfRange

This is not necessarily undefined behavior, but can lead to nasty surprises, so projects may decide to use a coding standard that disallows these "unusual" conversions. It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.core.EnumCastOutOfRange. It applies to C, C++.

Code
optin.core.EnumCastOutOfRange

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

Check for variadic functions that unconditionally use va_arg(). optin.core.UnconditionalVAArg

It is possible to use such functions safely (as long as they always receive at least one variadic argument), but their careless use can lead to undefined behavior (trying to access a variadic argument when there isn't any), so it is better to avoid them. It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.core.UnconditionalVAArg. It applies to C, C++.

Code
optin.core.UnconditionalVAArg

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

This checker reports uninitialized fields in objects created after a constructor call. optin.cplusplus.UninitializedObject

It doesn't only find direct uninitialized fields, but rather makes a deep inspection of the object, analyzing all of its fields' subfields. The checker regards inherited fields as direct fields, so one will receive warnings for uninitialized inherited data members as well. It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.cplusplus.UninitializedObject. It applies to C++.

Code
optin.cplusplus.UninitializedObject

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

When virtual methods are called during construction and destruction the polymorphism is restricted to the class that's being constructed or destructed because the more derived contexts are either not yet initialized or already destructed. optin.cplusplus.VirtualCall

It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.cplusplus.VirtualCall. It applies to C++.

Code
optin.cplusplus.VirtualCall

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

Taint analysis identifies potential security vulnerabilities where the attacker can inject malicious data to the program to execute an attack (privilege escalation, command injection, SQL injection etc.). optin.taint.GenericTaint

It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.taint.GenericTaint. It applies to C, C++.

Code
optin.taint.GenericTaint

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

This checker warns for cases when the size parameter of the malloc , calloc, realloc, alloca or the size parameter of the array new C++ operator is tainted (potentially attacker controlled). optin.taint.TaintedAlloc

If an attacker can inject a large value as the size parameter, memory exhaustion denial of service attack can be carried out. It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.taint.TaintedAlloc. It applies to C, C++.

Code
optin.taint.TaintedAlloc

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

This checker warns when the denominator in a division operation is a tainted (potentially attacker controlled) value. optin.taint.TaintedDiv

If the attacker can set the denominator to 0, a runtime error can be triggered. The checker warns when the denominator is a tainted value and the analyzer cannot prove that it is not 0. It is an opt-in checker, so the analyzer runs it only when you enable it. clang-tidy runs it as the check clang-analyzer-optin.taint.TaintedDiv. It applies to C, C++, Objective-C.

Code
optin.taint.TaintedDiv

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

Recommends the smallest possible underlying type for an enum or enum class based on the range of its enumerators. performance-enum-size

Analyzes the values of the enumerators in an enum or enum class, including signed values, to recommend the smallest possible underlying type that can represent all the values of the enum. The suggested underlying types are the integral types std::uint8_t, std::uint16_t, and std::uint32_t for unsigned types, and std::int8_t, std::int16_t, and std::int32_t for signed types. The check is in the performance module of clang-tidy.

Code
performance-enum-size

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

Finds calls to value_or (and alternative spellings valueOr, ValueOr) on optional types where the return type is expensive to copy. performance-expensive-value-or

These methods return by value, which involves copying the contained value. value() and operator* return references and can be used to avoid the copy when appropriate. clang-tidy can fix the code that it finds. The check is in the performance module of clang-tidy.

Code
performance-expensive-value-or

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

Finds potentially erroneous calls to reset method on smart pointers when the pointee type also has a reset method. readability-ambiguous-smartptr-reset-call

Having a reset method in both classes makes it easy to accidentally make the pointer null when intending to reset the underlying object. clang-tidy can fix the code that it finds. The check is in the readability module of clang-tidy.

Code
readability-ambiguous-smartptr-reset-call

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

Finds cases where code could use data() rather than the address of the element at index 0 in a container. readability-container-data-pointer

This pattern is commonly used to materialize a pointer to the backing data of a container. std::vector and std::string provide a data() accessor to retrieve the data pointer which should be preferred. clang-tidy can fix the code that it finds. The check is in the readability module of clang-tidy.

Code
readability-container-data-pointer

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

LLVM Coding Standards advises to reduce indentation where possible and where it makes understanding code easier. readability-else-after-return

Early exit is one of the suggested enforcements of that. Please do not use else or else if after something that interrupts control flow - like return, break, continue, throw. clang-tidy can fix the code that it finds. The check is in the readability module of clang-tidy.

Code
readability-else-after-return

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

This check can be used to find implicit conversions between built-in types and booleans. readability-implicit-bool-conversion

Depending on use case, it may simply help with readability of the code, or in some cases, point to potential bugs which remain unnoticed due to implicit conversions. clang-tidy can fix the code that it finds. The check is in the readability module of clang-tidy.

Code
readability-implicit-bool-conversion

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

Detects explicit type casting operations that involve the same source and destination types, and subsequently recommend their removal. readability-redundant-casting

Covers a range of explicit casting operations, including static_cast, const_cast, C-style casts, and reinterpret_cast. Its primary objective is to enhance code readability and maintainability by eliminating unnecessary type casting. clang-tidy can fix the code that it finds. The check is in the readability module of clang-tidy.

Code
readability-redundant-casting

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

Check for calls to blocking functions inside a critical section. unix.BlockInCriticalSection

Blocking functions detected by this checker: sleep, getc, fgets, read, recv. Critical section handling functions modeled by this checker: lock, unlock, pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_unlock, mtx_lock, mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock, scoped_lock. clang-tidy runs it as the check clang-analyzer-unix.BlockInCriticalSection. It applies to C, C++.

Code
unix.BlockInCriticalSection

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

The goal of this rule is to make sure the constructors of RetainPtr and OSObjectPtr as well as adoptNS, adoptCF, and adoptOSObject are used correctly. webkit.RetainPtrCtorAdoptChecker

When creating a RetainPtr or OSObjectPtr with +1 semantics, adoptNS, adoptCF, or adoptOSObject should be used, and in +0 semantics, RetainPtr or OSObjectPtr constructor should be used. Warn otherwise. It is an experimental (alpha) checker, so the analyzer does not run it by default.

Code
webkit.RetainPtrCtorAdoptChecker

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