Programming Search⌘K

C++ lints, page 1 of 3

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

Checks for cases where addition should be performed in the absl::Time domain. abseil-duration-addition

When adding two values, and one is known to be an absl::Time, we can infer that the other should be interpreted as an absl::Duration of a similar scale, and make that inference explicit. clang-tidy can fix the code that it finds. The check is in the abseil module of clang-tidy.

Code
abseil-duration-addition

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

Checks for cases where subtraction should be performed in the absl::Duration domain. abseil-duration-subtraction

When subtracting two values, and the first one is known to be a conversion from absl::Duration, we can infer that the second should also be interpreted as an absl::Duration, and make that inference explicit. clang-tidy can fix the code that it finds. The check is in the abseil module of clang-tidy.

Code
abseil-duration-subtraction

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

Finds instances of absl::StrSplit() or absl::MaxSplits() where the delimiter is a single character string literal and replaces with a character. abseil-faster-strsplit-delimiter

The check will offer a suggestion to change the string literal into a character. It will also catch code using absl::ByAnyChar() for just a single character and will transform that into a single character as well. clang-tidy can fix the code that it finds. The check is in the abseil module of clang-tidy.

Code
abseil-faster-strsplit-delimiter

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

Check if a value of active type is retrieved from an std::variant instance with std::get. alpha.core.StdVariant

In case of bad variant type access (the accessed type differs from the active type) a warning is emitted. Currently, this checker does not take exception handling into account. It is an experimental (alpha) checker, so the analyzer does not run it by default. It applies to C++.

Code
alpha.core.StdVariant

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

Check for returned pointers and references that are bound to an object whose lifetime ends when the function returns. alpha.core.UseAfterLifetimeEnd

The checker only analyzes code that is annotated with the [[clang::lifetimebound]] attribute. The annotation tells the checker which object the returned value is bound to. It is an experimental (alpha) checker, so the analyzer does not run it by default. It applies to C, C++.

Code
alpha.core.UseAfterLifetimeEnd

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

Raw pointers and references to a NS or CF object can't be used as class members or ivars. alpha.webkit.NoUnretainedMemberChecker

Only RetainPtr is allowed for CF types regardless of whether ARC is enabled or disabled. Only RetainPtr or OSObjectPtr is allowed for NS types when ARC is disabled. It is an experimental (alpha) checker, so the analyzer does not run it by default.

Code
alpha.webkit.NoUnretainedMemberChecker

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 that lifetime of any dynamically allocated CheckedPtr capable object passed as a call argument keeps its memory region past the end of the call. alpha.webkit.UncheckedCallArgsChecker

This applies to call to any function, method, lambda, function pointer or functor. CheckedPtr capable objects aren't supposed to be allocated on stack so we check arguments for parameters of raw pointers and references to unchecked types. It is an experimental (alpha) checker, so the analyzer does not run it by default.

Code
alpha.webkit.UncheckedCallArgsChecker

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 that any unchecked local variable is backed by a CheckedPtr or CheckedRef with lifetime that is strictly larger than the scope of the unchecked local variable. alpha.webkit.UncheckedLocalVarsChecker

To be on the safe side we require the scope of an unchecked variable to be embedded in the scope of CheckedPtr/CheckRef object that backs it. It is an experimental (alpha) checker, so the analyzer does not run it by default.

Code
alpha.webkit.UncheckedLocalVarsChecker

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 that lifetime of any dynamically allocated ref-countable object passed as a call argument spans past the end of the call. alpha.webkit.UncountedCallArgsChecker

This applies to call to any function, method, lambda, function pointer or functor. Ref-countable types aren't supposed to be allocated on stack so we check arguments for parameters of raw pointers and references to uncounted types. It is an experimental (alpha) checker, so the analyzer does not run it by default.

Code
alpha.webkit.UncountedCallArgsChecker

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 that any uncounted local variable is backed by a ref-counted object with lifetime that is strictly larger than the scope of the uncounted local variable. alpha.webkit.UncountedLocalVarsChecker

To be on the safe side we require the scope of an uncounted variable to be embedded in the scope of ref-counted object that backs it. It is an experimental (alpha) checker, so the analyzer does not run it by default.

Code
alpha.webkit.UncountedLocalVarsChecker

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 that lifetime of any dynamically allocated NS or CF objects passed as a call argument keeps its memory region past the end of the call. alpha.webkit.UnretainedCallArgsChecker

This applies to call to any function, method, lambda, function pointer or functor. NS or CF objects aren't supposed to be allocated on stack so we check arguments for parameters of raw pointers and references to unretained types. It is an experimental (alpha) checker, so the analyzer does not run it by default.

Code
alpha.webkit.UnretainedCallArgsChecker

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

Raw pointers and references to NS or CF types can't be captured in lambdas. alpha.webkit.UnretainedLambdaCapturesChecker

Only RetainPtr is allowed for CF types regardless of whether ARC is enabled or disabled, and only RetainPtr or OSObjectPtr is allowed for NS types when ARC is disabled. It is an experimental (alpha) checker, so the analyzer does not run it by default.

Code
alpha.webkit.UnretainedLambdaCapturesChecker

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 that any NS or CF local variable is backed by a RetainPtr or OSObjectPtr with lifetime that is strictly larger than the scope of the unretained local variable. alpha.webkit.UnretainedLocalVarsChecker

To be on the safe side we require the scope of an unretained variable to be embedded in the scope of RetainPtr or OSObjectPtr object that backs it. It is an experimental (alpha) checker, so the analyzer does not run it by default.

Code
alpha.webkit.UnretainedLocalVarsChecker

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

A common source of security bugs is code that opens a file without using the O_CLOEXEC flag. android-cloexec-open

Without that flag, an opened sensitive file would remain open across a fork+exec to a lower-privileged SELinux domain, leaking that sensitive data. Open-like functions including open(), openat(), and open64() should include O_CLOEXEC in their flags argument. clang-tidy can fix the code that it finds. The check is in the android module of clang-tidy.

Code
android-cloexec-open

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

This check ensures that pipe2() is called with the O_CLOEXEC flag. android-cloexec-pipe2

The check also adds the O_CLOEXEC flag that marks the file descriptor to be closed in child processes. Without this flag a sensitive file descriptor can be leaked to a child process, potentially into a lower-privileged SELinux domain. clang-tidy can fix the code that it finds. The check is in the android module of clang-tidy.

Code
android-cloexec-pipe2

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

Finds assignments within selection statements. bugprone-assignment-in-selection-statement

Such assignments may indicate programmer error because they may have been intended as equality tests. The selection statements are conditions of if and loop (for, while, do) statements, condition of conditional operator (?:) and any operand of a binary logical operator (&&, ||). The check is in the bugprone module of clang-tidy.

Code
bugprone-assignment-in-selection-statement

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

The check looks for perfect forwarding constructors that can hide copy or move constructors. bugprone-forwarding-reference-overload

If a non const lvalue reference is passed to the constructor, the forwarding reference parameter will be a better match than the const reference parameter of the copy constructor, so the perfect forwarding constructor will be called, which can be confusing. For detailed description of this issue see: Scott Meyers, Effective Modern C++, Item 26. The check is in the bugprone module of clang-tidy.

Code
bugprone-forwarding-reference-overload

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

The check diagnoses instances where a result of a multiplication is implicitly widened, and suggests (with fix-it) to either silence the code by making widening explicit, or to perform the multiplication in a wider type, to avoid the widening afterwards. bugprone-implicit-widening-of-multiplication-result

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

Code
bugprone-implicit-widening-of-multiplication-result

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

Finds cases where 1 is added to the string in the argument to strlen(), strnlen(), strnlen_s(), wcslen(), wcsnlen(), and wcsnlen_s() instead of the result and the value is used as an argument to a memory allocation function (malloc(), calloc(), realloc(), alloca()) or the new[] operator in C++. The check detects error cases even if one of these functions (except the new[] operator) is called by a constant function pointer. bugprone-misplaced-operator-in-strlen-in-alloc

Cases where 1 is added both to the parameter and the result of the strlen()-like function are ignored, as are cases where the whole addition is surrounded by extra parentheses. clang-tidy can fix the code that it finds. The check is in the bugprone module of clang-tidy.

Code
bugprone-misplaced-operator-in-strlen-in-alloc

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

Finds cases where an integer expression is added to or subtracted from the result of a memory allocation function (malloc(), calloc(), realloc(), alloca()) instead of its argument. bugprone-misplaced-pointer-arithmetic-in-alloc

The check detects error cases even if one of these functions is called by a constant function pointer. clang-tidy can fix the code that it finds. The check is in the bugprone module of clang-tidy.

Code
bugprone-misplaced-pointer-arithmetic-in-alloc

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

Detect implicit and explicit casts of enum type into bool where enum type doesn't have a zero-value enumerator. bugprone-non-zero-enum-to-bool-conversion

If the enum is used only to hold values equal to its enumerators, then conversion to bool will always result in true value. This can lead to unnecessary code that reduces readability and maintainability and can result in bugs. The check is in the bugprone module of clang-tidy.

Code
bugprone-non-zero-enum-to-bool-conversion

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

Finds function calls where it is possible to cause a not null-terminated result. bugprone-not-null-terminated-result

Usually the proper length of a string is strlen(src) + 1 or equal length of this expression, because the null terminator needs an extra space. Without the null terminator it can result in undefined behavior when the string is read. clang-tidy can fix the code that it finds. The check is in the bugprone module of clang-tidy.

Code
bugprone-not-null-terminated-result

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

Flags all pseudo-random number engines, engine adaptor instantiations and srand() when initialized or seeded with default argument, constant expression or any user-configurable type. bugprone-random-generator-seed

Pseudo-random number engines seeded with a predictable value may cause vulnerabilities e.g. in security protocols. The check is in the bugprone module of clang-tidy.

Code
bugprone-random-generator-seed

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

Checks for various ways that the const CharT* constructor of std::basic_string_view can be passed a null argument and replaces them with the default constructor in most cases. bugprone-stringview-nullptr

For the comparison operators, braced initializer list does not compile so instead a call to .empty() or the empty string literal are used, where appropriate. clang-tidy can fix the code that it finds. The check is in the bugprone module of clang-tidy.

Code
bugprone-stringview-nullptr

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

This check finds usages of realloc where the return value is assigned to the same expression as passed to the first argument. bugprone-suspicious-realloc-usage

If no other variable is pointing to it, the original memory block is not available any more for the program to use or free. In either case p = realloc(p, size); indicates bad coding style and can be replaced by q = realloc(p, size). The check is in the bugprone module of clang-tidy.

Code
bugprone-suspicious-realloc-usage

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

Finds most instances of stray semicolons that unexpectedly alter the meaning of the code. bugprone-suspicious-semicolon

More specifically, it looks for if, while, for and for-range statements whose body is a single semicolon, and then analyzes the context of the code (e.g. indentation) in an attempt to determine whether that is intentional. clang-tidy can fix the code that it finds. The check is in the bugprone module of clang-tidy.

Code
bugprone-suspicious-semicolon

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

Finds potentially swapped arguments by examining implicit conversions. bugprone-swapped-arguments

It analyzes the types of the arguments being passed to a function and compares them to the expected types of the corresponding parameters. If there is a mismatch or an implicit conversion that indicates a potential swap, a warning is raised. clang-tidy can fix the code that it finds. The check is in the bugprone module of clang-tidy.

Code
bugprone-swapped-arguments

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