From 89ca492439f4fcd61b159b33ec613d3b16c063af Mon Sep 17 00:00:00 2001
From: guwirth
Warns if code using Abseil depends on internal details. If something is in a namespace that includes the word 'internal', code is not allowed to depend upon it beaucse it's an implementation detail. They cannot friend it, include it, you mention it or refer to it in any way. Doing so violates Abseil's compatibility guidelines and may result in breakage. See https://abseil.io/about/compatibility for more information.
+Warns if code using Abseil depends on internal details. If something is in a namespace that includes the word "internal", code is not allowed to depend upon it because it's an implementation detail. They cannot friend it, include it, you mention it or refer to it in any way. Doing so violates Abseil's compatibility guidelines and may result in breakage. See https://abseil.io/about/compatibility for more information.
The following cases will result in warnings:
absl::strings_internal::foo();
// warning triggered on this line
@@ -392,7 +392,7 @@ absl::memory_internal::MakeUniqueResult();
...
}
will be prompted with a warning.
-See the full Abseil compatibility guidelines <https://abseil.io/about/compatibility> for more information.
+See the full Abseil compatibility guidelines <https:// abseil.io/about/compatibility> for more information.
int x;
absl::Time t;
-// Original - absl::Duration result and first operand is a absl::Time.
+// Original - absl::Duration result and first operand is an absl::Time.
absl::Duration d = absl::Seconds(absl::ToUnixSeconds(t) - x);
// Suggestion - Perform subtraction in the Time domain instead.
@@ -613,6 +613,35 @@ d *= static_cast<int64_t>(a);
clang-tidy - altera-id-dependent-backward-branch
+ +Finds ID-dependent variables and fields that are used within loops. This causes branches to occur inside the loops, and thus leads to performance degradation.
+// The following code will produce a warning because this ID-dependent
+// variable is used in a loop condition statement.
+int ThreadID = get_local_id(0);
+// The following loop will produce a warning because the loop condition
+// statement depends on an ID-dependent variable.
+for (int i = 0; i < ThreadID; ++i) {
+ std::cout << i << std::endl;
+}
+// The following loop will not produce a warning, because the ID-dependent
+// variable is not used in the loop condition statement.
+for (int i = 0; i < 100; ++i) {
+ std::cout << ThreadID << std::endl;
+}
+Based on the Altera SDK for OpenCL: Best Practices Guide.
+clang-tidy - android-cloexec-pipe2
This checks ensures that pipe2() is called with the O_CLOEXEC flag. 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.
+This check ensures that pipe2() is called with the O_CLOEXEC flag. 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.
Examples:
pipe2(pipefd, O_NONBLOCK);
Suggested replacement:
@@ -1180,7 +1209,7 @@ while (TEMP_FAILURE_RETRY(read(STDIN_FILENO, cs, sizeof(cs))) != 0) {This check finds conversion from integer type like int
to std::string
or std::wstring
using boost::lexical_cast
, and replace it with calls to std::to_string
and std::to_wstring
.
It doesn't replace conversion from floating points despite the to_string
overloads, because it would change the behaviour.
It doesn't replace conversion from floating points despite the to_string
overloads, because it would change the behavior.
auto str = boost::lexical_cast<std::string>(42);
auto wstr = boost::lexical_cast<std::wstring>(2137LL);
@@ -1439,7 +1468,7 @@ default:
Finally, the check also examines conditional operators and reports code like:
return test_value(x) ? x : x;
Unlike if statements, the check does not detect chains of conditional operators.
-Note: This check also reports situations where branches become identical only after preprocession.
+Note: This check also reports situations where branches become identical only after preprocessing.
References
]]>
@@ -1484,7 +1513,7 @@ class X2 : public Copyable {
clang-tidy - bugprone-dangling-handle
bugprone-dangling-handle
-Detect dangling references in value handles like std::experimental::string_view
. These dangling references can be a result of constructing handles from temporary values, where the temporary is destroyed soon after the handle is created.
+Detect dangling references in value handles like std::string_view
. These dangling references can be a result of constructing handles from temporary values, where the temporary is destroyed soon after the handle is created.
Examples:
string_view View = string(); // View will dangle.
string A;
@@ -1505,7 +1534,7 @@ string_view f() {
Options
HandleClasses
-A semicolon-separated list of class names that should be treated as handles. By default only std::experimental::basic_string_view
is considered.
+A semicolon-separated list of class names that should be treated as handles. By default only std::basic_string_view
and std::experimental::basic_string_view
are considered.
References
]]>
@@ -1537,6 +1566,136 @@ string_view f() {
INFO
CODE_SMELL
clang-tidy - bugprone-easily-swappable-parameters
+ +Finds function definitions where parameters of convertible types follow each other directly, making call sites prone to calling the function with swapped (or badly ordered) arguments.
+void drawPoint(int X, int Y) { /* ... */ }
+FILE *open(const char *Dir, const char *Name, Flags Mode) { /* ... */ }
+A potential call like drawPoint(-2, 5)
or openPath("a.txt", "tmp", Read)
is perfectly legal from the language's perspective, but might not be what the developer of the function intended.
More elaborate and type-safe constructs, such as opaque typedefs or strong types should be used instead, to prevent a mistaken order of arguments.
+struct Coord2D { int X; int Y; };
+void drawPoint(const Coord2D Pos) { /* ... */ }
+FILE *open(const Path &Dir, const Filename &Name, Flags Mode) { /* ... */ }
+Due to the potentially elaborate refactoring and API-breaking that is necessary to strengthen the type safety of a project, no automatic fix-its are offered.
+Relaxation (or extension) options can be used to broaden the scope of the analysis and fine-tune the enabling of more mixes between types. Some mixes may depend on coding style or preference specific to a project, however, it should be noted that enabling all of these relaxations model the way of mixing at call sites the most. These options are expected to make the check report for more functions, and report longer mixable ranges.
+QualifiersMix
+Whether to consider parameters of some cvr-qualified T
and a differently cvr-qualified T
(i.e. T
and const T
, const T
and volatile T
, etc.) mixable between one another. If false, the check will consider differently qualified types unmixable. True turns the warnings on. Defaults to false.
The following example produces a diagnostic only if QualifiersMix is enabled:
+void *memcpy(const void *Destination, void *Source, std::size_t N) { /* ... */ }
+ModelImplicitConversions
+Whether to consider parameters of type T
and U
mixable if there exists an implicit conversion from T
to U
and U
to T
. If false, the check will not consider implicitly convertible types for mixability. True turns warnings for implicit conversions on. Defaults to true.
The following examples produce a diagnostic only if ModelImplicitConversions is enabled:
+void fun(int Int, double Double) { /* ... */ }
+void compare(const char *CharBuf, std::string String) { /* ... */ }
+Note
+Changing the qualifiers of an expression's type (e.g. from int
to const int
) is defined as an implicit conversion in the C++ Standard. However, the check separates this decision-making on the mixability of differently qualified types based on whether QualifiersMix was enabled.
For example, the following code snippet will only produce a diagnostic if both QualifiersMix and ModelImplicitConversions are enabled:
+void fun2(int Int, const double Double) { /* ... */ }
+Filtering options can be used to lessen the size of the diagnostics emitted by the checker, whether the aim is to ignore certain constructs or dampen the noisiness.
+MinimumLength
+The minimum length required from an adjacent parameter sequence to be diagnosed. Defaults to 2. Might be any positive integer greater or equal to 2. If 0 or 1 is given, the default value 2 will be used instead.
+For example, if 3 is specified, the examples above will not be matched.
+IgnoredParameterNames
+The list of parameter names that should never be considered part of a swappable adjacent parameter sequence. The value is a ;-separated list of names. To ignore unnamed parameters, add "" to the list verbatim (not the empty string, but the two quotes, potentially escaped!). This option is case-sensitive!
+By default, the following parameter names, and their Uppercase-initial variants are ignored: "" (unnamed parameters), iterator, begin, end, first, last, lhs, rhs.
+IgnoredParameterTypeSuffixes
+The list of parameter type name suffixes that should never be considered part of a swappable adjacent parameter sequence. Parameters which type, as written in the source code, end with an element of this option will be ignored. The value is a ;-separated list of names. This option is case-sensitive!
+By default, the following, and their lowercase-initial variants are ignored: bool, It, Iterator, InputIt, ForwardIt, BidirIt, RandomIt, random_iterator, ReverseIt, reverse_iterator, reverse_const_iterator, RandomIt, random_iterator, ReverseIt, reverse_iterator, reverse_const_iterator, Const_Iterator, ConstIterator, const_reverse_iterator, ConstReverseIterator. In addition, _Bool (but not _bool) is also part of the default value.
+SuppressParametersUsedTogether
+Suppresses diagnostics about parameters that are used together or in a similar fashion inside the function's body. Defaults to true. Specifying false will turn off the heuristics.
+Currently, the following heuristics are implemented which will suppress the warning about the parameter pair involved:
+The parameters are used in the same expression, e.g. f(a, b)
or a < b
.
The parameters are further passed to the same function to the same parameter of that function, of the same overload. e.g. f(a, 1)
and f(b, 2)
to some f(T, int)
.
Note
+The check does not perform path-sensitive analysis, and as such, "same function" in this context means the same function declaration. If the same member function of a type on two distinct instances are called with the parameters, it will still be regarded as "same function".
+The same member field is accessed, or member method is called of the two parameters, e.g. a.foo()
and b.foo()
.
Separate return
statements return either of the parameters on different code paths.
NamePrefixSuffixSilenceDissimilarityTreshold
+The number of characters two parameter names might be different on either the head or the tail end with the rest of the name the same so that the warning about the two parameters are silenced. Defaults to 1. Might be any positive integer. If 0, the filtering heuristic based on the parameters' names is turned off.
+This option can be used to silence warnings about parameters where the naming scheme indicates that the order of those parameters do not matter.
+For example, the parameters LHS
and RHS
are 1-dissimilar suffixes of each other: L
and R
is the different character, while HS
is the common suffix. Similarly, parameters text1, text2, text3
are 1-dissimilar prefixes of each other, with the numbers at the end being the dissimilar part. If the value is at least 1, such cases will not be reported.
This check is designed to check function signatures!
+The check does not investigate functions that are generated by the compiler in a context that is only determined from a call site. These cases include variadic functions, functions in C code that do not have an argument list, and C++ template instantiations. Most of these cases, which are otherwise swappable from a caller's standpoint, have no way of getting "fixed" at the definition point. In the case of C++ templates, only primary template definitions and explicit specializations are matched and analyzed.
+None of the following cases produce a diagnostic:
+int printf(const char *Format, ...) { /* ... */ }
+int someOldCFunction() { /* ... */ }
+template <typename T, typename U>
+int add(T X, U Y) { return X + Y };
+void theseAreNotWarnedAbout() {
+ printf("%d %d\n", 1, 2); // Two ints passed, they could be swapped.
+ someOldCFunction(1, 2, 3); // Similarly, multiple ints passed.
+ add(1, 2); // Instantiates 'add<int, int>', but that's not a user-defined function.
+}
+Due to the limitation above, parameters which type are further dependent upon template instantiations to prove that they mix with another parameter's is not diagnosed.
+template <typename T>
+struct Vector {
+ typedef T element_type;
+};
+// Diagnosed: Explicit instantiation was done by the user, we can prove it
+// is the same type.
+void instantiated(int A, Vector<int>::element_type B) { /* ... */ }
+// Diagnosed: The two parameter types are exactly the same.
+template <typename T>
+void exact(typename Vector<T>::element_type A,
+ typename Vector<T>::element_type B) { /* ... */ }
+// Skipped: The two parameters are both 'T' but we cannot prove this
+// without actually instantiating.
+template <typename T>
+void falseNegative(T A, typename Vector<T>::element_type B) { /* ... */ }
+In the context of implicit conversions (when ModelImplicitConversions is enabled), the modelling performed by the check warns if the parameters are swappable and the swapped order matches implicit conversions. It does not model whether there exists an unrelated third type from which both parameters can be given in a function call. This means that in the following example, even while strs()
clearly carries the possibility to be called with swapped arguments (as long as the arguments are string literals), will not be warned about.
struct String {
+ String(const char *Buf);
+};
+struct StringView {
+ StringView(const char *Buf);
+ operator const char *() const;
+};
+// Skipped: Directly swapping expressions of the two type cannot mix.
+// (Note: StringView -> const char * -> String would be **two**
+// user-defined conversions, which is disallowed by the language.)
+void strs(String Str, StringView SV) { /* ... */ }
+// Diagnosed: StringView implicitly converts to and from a buffer.
+void cStr(StringView SV, const char *Buf() { /* ... */ }
+The check flags type mismatches in folds like std::accumulate
that might result in loss of precision. std::accumulate
folds an input range into an initial value using the type of the latter, with operator+
by default. This can cause loss of precision through:
operator+
and the result will be 0, which might not be what the user expected.operator+
and the result will be 0, which might not be what the user expected.auto a = {0.5f, 0.5f, 0.5f, 0.5f};
return std::accumulate(std::begin(a), std::end(a), 0);
@@ -1649,12 +1808,16 @@ public:
template<typename T, typename X = enable_if_t<is_special<T>,void>>
explicit Person(T&& n) {}
+ // C4: variadic perfect forwarding ctor guarded with enable_if
+ template<typename... A,
+ enable_if_t<is_constructible_v<tuple<string, int>, A&&...>, int> = 0>
+ explicit Person(A&&... a) {}
// (possibly compiler generated) copy ctor
Person(const Person& rhs);
};
-The check warns for constructors C1 and C2, because those can hide copy and move constructors. We suppress warnings if the copy and the move constructors are both disabled (deleted or private), because there is nothing the perfect forwarding constructor could hide in this case. We also suppress warnings for constructors like C3 that are guarded with an enable_if
, assuming the programmer was aware of the possible hiding.
The check warns for constructors C1 and C2, because those can hide copy and move constructors. We suppress warnings if the copy and the move constructors are both disabled (deleted or private), because there is nothing the perfect forwarding constructor could hide in this case. We also suppress warnings for constructors like C3 and C4 that are guarded with an enable_if
, assuming the programmer was aware of the possible hiding.
For deciding whether a constructor is guarded with enable_if, we consider the default values of the type parameters and the types of the constructor parameters. If any part of these types is std::enable_if
or std::enable_if_t
, we assume the constructor is guarded.
For deciding whether a constructor is guarded with enable_if, we consider the types of the constructor parameters, the default values of template type parameters and the types of non-type template parameters with a default literal value. If any part of these types is std::enable_if
or std::enable_if_t
, we assume the constructor is guarded.
clang-tidy - bugprone-implicit-widening-of-multiplication-result
+ +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.
+This is mainly useful when operating on very large buffers. For example, consider:
+void zeroinit(char* base, unsigned width, unsigned height) {
+ for(unsigned row = 0; row != height; ++row) {
+ for(unsigned col = 0; col != width; ++col) {
+ char* ptr = base + row * width + col;
+ *ptr = 0;
+ }
+ }
+}
+This is fine in general, but if width * height
overflows, you end up wrapping back to the beginning of base
instead of processing the entire requested buffer.
Indeed, this only matters for pretty large buffers (4GB+), but that can happen very easily for example in image processing, where for that to happen you "only" need a ~269MPix image.
+UseCXXStaticCastsInCppSources
+When suggesting fix-its for C++ code, should C++-style static_cast<>()
's be suggested, or C-style casts. Defaults to true
.
UseCXXHeadersInCppSources
+When suggesting to include the appropriate header in C++ code, should <cstddef>
header be suggested, or <stddef.h>
. Defaults to true
.
Examples:
+long mul(int a, int b) {
+ return a * b; // warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'int'
+}
+char* ptr_add(char *base, int a, int b) {
+ return base + a * b; // warning: result of multiplication in type 'int' is used as a pointer offset after an implicit widening conversion to type 'ssize_t'
+}
+char ptr_subscript(char *base, int a, int b) {
+ return base[a * b]; // warning: result of multiplication in type 'int' is used as a pointer offset after an implicit widening conversion to type 'ssize_t'
+}
+clang-tidy - bugprone-macro-parentheses
Finds macros that can have unexpected behaviour due to missing parentheses.
-Macros are expanded by the preprocessor as-is. As a result, there can be unexpected behaviour; operators may be evaluated in unexpected order and unary operators may become binary operators, etc.
+Finds macros that can have unexpected behavior due to missing parentheses.
+Macros are expanded by the preprocessor as-is. As a result, there can be unexpected behavior; operators may be evaluated in unexpected order and unary operators may become binary operators, etc.
When the replacement list has an expression, it is recommended to surround it with parentheses. This ensures that the macro result is evaluated completely before it is used.
It is also recommended to surround macro arguments in the replacement list with parentheses. This ensures that the argument value is calculated properly.
CheckImplicitCasts
-If true, enables detection of implicit casts. Default is true.
+If true, enables detection of implicit casts. Default is false.
clang-tidy - bugprone-not-null-terminated-result
Finds function calls where it is possible to cause a 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 behaviour when the string is read.
Finds function calls where it is possible to cause a 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.
The following and their respective wchar_t
based functions are checked:
memcpy
, memcpy_s
, memchr
, memmove
, memmove_s
, strerror_s
, strncmp
, strxfrm
The following is a real-world example where the programmer forgot to increase the passed third argument, which is size_t length
. That is why the length of the allocated memory is not enough to hold the null terminator.
cpy
), because it is more efficient than the safe version.WantToUseSafeFunctions
is set to true and it is possible to obtain the capacity of the destination array then the new function could be the safe version (ending with cpy_s
).char
/wchar_t
without un/signed
then the length of the destination array can be omitted.char
/wchar_t
without un/signed
then the length of the destination array can be omitted.un/signed
it needs to be casted to plain char *
/wchar_t *
.In the first case (logical "and") the suggested fix is to remove the redundant condition variable and keep the other side of the &&
. In the second case (logical "or") the whole if
is removed similarily to the simple case on the top.
In the first case (logical "and") the suggested fix is to remove the redundant condition variable and keep the other side of the &&
. In the second case (logical "or") the whole if
is removed similarly to the simple case on the top.
The condition of the outer if
statement may also be a logical "and" (&&
) expression:
bool onFire = isBurning();
if (onFire && fireFighters < 10) {
@@ -2238,7 +2446,7 @@ if (onFire) {
#define cool__macro // also this
}
int _g(); // disallowed in global namespace only
-The check can also be inverted, i.e. it can be configured to flag any identifier that is not a reserved identifier. This mode is for use by e.g. standard library implementors, to ensure they don't infringe on the user namespace.
+The check can also be inverted, i.e. it can be configured to flag any identifier that is _not a reserved identifier. This mode is for use by e.g. standard library implementors, to ensure they don't infringe on the user namespace.
This check does not (yet) check for other reserved names, e.g. macro names identical to language keywords, and names specifically reserved by language standards, e.g. C++ 'zombie names' and C future library directions.
This check corresponds to CERT C Coding Standard rule DCL37-C. Do not declare or define a reserved identifier as well as its C++ counterpart, DCL51-CPP. Do not declare or define a reserved identifier.
This check corresponds to the CERT C Coding Standard rule SIG30-C. Call only asynchronous-safe functions within signal handlers and has an alias name cert-sig30-c
.
AsyncSafeFunctionSet
-Selects wich set of functions is considered as asynchronous-safe (and therefore allowed in signal handlers). Value minimal
selects a minimal set that is defined in the CERT SIG30-C rule and includes functions abort()
, _Exit()
, quick_exit()
and signal()
. Value POSIX
selects a larger set of functions that is listed in POSIX.1-2017 (see this link for more information). The function quick_exit
is not included in the shown list. It is assumable that the reason is that the list was not updated for C11. The checker includes quick_exit
in the set of safe functions. Functions registered as exit handlers are not checked.
Selects which set of functions is considered as asynchronous-safe (and therefore allowed in signal handlers). Value minimal
selects a minimal set that is defined in the CERT SIG30-C rule and includes functions abort()
, _Exit()
, quick_exit()
and signal()
. Value POSIX
selects a larger set of functions that is listed in POSIX.1-2017 (see this link for more information). The function quick_exit
is not included in the shown list. It is assumable that the reason is that the list was not updated for C11. The checker includes quick_exit
in the set of safe functions. Functions registered as exit handlers are not checked.
Default is POSIX
.
WarnOnSizeOfCompareToConstant
-When true, the check will warn on an expression like sizeof(epxr) <= k
for a suspicious constant k while k is 0 or greater than 0x8000. Default is true.
When true, the check will warn on an expression like sizeof(expr) <= k
for a suspicious constant k while k is 0 or greater than 0x8000. Default is true.
clang-tidy - bugprone-suspicious-memory-comparison
+ +Finds potentially incorrect calls to memcmp()
based on properties of the arguments. The following cases are covered:
Case 1: Non-standard-layout type
+Comparing the object representations of non-standard-layout objects may not properly compare the value representations.
+Case 2: Types with no unique object representation
+Objects with the same value may not have the same object representation. This may be caused by padding or floating-point types.
+See also: EXP42-C. Do not compare padding data and FLP37-C. Do not use object representations to compare floating-point values
+This check is also related to and partially overlaps the CERT C++ Coding Standard rules OOP57-CPP. Prefer special member functions and overloaded operators to C Standard Library functions and EXP62-CPP. Do not access the bits of an object representation that are not part of the object's value representation
+if (strcmp(...)) // Implicitly compare to zero
if (!strcmp(...)) // Won't warn
if (strcmp(...) != 0) // Won't warn
-Checks that compare function results (i,e, strcmp
) are compared to valid constant. The resulting value is
Checks that compare function results (i.e., strcmp
) are compared to valid constant. The resulting value is
< 0 when lower than,
> 0 when greater than,
== 0 when equals.
@@ -2980,10 +3209,10 @@ do {
int doSomething(const std::vector& items) {
for (short i = 0; i < items.size(); ++i) {}
}
-This algorithm works for small amount of objects, but will lead to freeze for a a larger user input.
+This algorithm works for a small amount of objects, but will lead to freeze for a larger user input.
MagnitudeBitsUpperLimit
-Upper limit for the magnitude bits of the loop variable. If it's set the check filters out those catches in which the loop variable's type has more magnitude bits as the specified upper limit. The default value is 16. For example, if the user sets this option to 31 (bits), then a 32-bit unsigend int
is ignored by the check, however a 32-bit int
is not (A 32-bit signed int
has 31 magnitude bits).
Upper limit for the magnitude bits of the loop variable. If it's set the check filters out those catches in which the loop variable's type has more magnitude bits as the specified upper limit. The default value is 16. For example, if the user sets this option to 31 (bits), then a 32-bit unsigned int
is ignored by the check, however a 32-bit int
is not (A 32-bit signed int
has 31 magnitude bits).
int main() {
long size = 294967296l;
@@ -3033,6 +3262,27 @@ do {
LINEAR
5min
clang-tidy - bugprone-unhandled-exception-at-new
+ +Finds calls to new
with missing exception handler for std::bad_alloc
.
int *f() noexcept {
+ int *p = new int[1000];
+ // ...
+ return p;
+}
+Calls to new
can throw exceptions of type std::bad_alloc
that should be handled by the code. Alternatively, the nonthrowing form of new
can be used. The check verifies that the exception is handled in the function that calls new
, unless a nonthrowing version is used or the exception is allowed to propagate out of the function (exception handler is checked for types std::bad_alloc
, std::exception
, and catch-all handler). The check assumes that any user-defined operator new
is either noexcept
or may throw an exception of type std::bad_alloc
(or derived from it). Other exception types or exceptions occurring in the object's constructor are not taken into account.
CheckedFunctions
-Semicolon-separated list of functions to check. Defaults to ::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty
. This means that the calls to following functions are checked by default:
Semicolon-separated list of functions to check. The function is checked if the name and scope matches, with any arguments. By default the following functions are checked: std::async, std::launder, std::remove, std::remove_if, std::unique, std::unique_ptr::release, std::basic_string::empty, std::vector::empty, std::back_inserter, std::distance, std::find, std::find_if, std::inserter, std::lower_bound, std::make_pair, std::map::count, std::map::find, std::map::lower_bound, std::multimap::equal_range, std::multimap::upper_bound, std::set::count, std::set::find, std::setfill, std::setprecision, std::setw, std::upper_bound, std::vector::at, bsearch, ferror, feof, isalnum, isalpha, isblank, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, iswalnum, iswprint, iswspace, isxdigit, memchr, memcmp, strcmp, strcoll, strncmp, strpbrk, strrchr, strspn, strstr, wcscmp, access, bind, connect, difftime, dlsym, fnmatch, getaddrinfo, getopt, htonl, htons, iconv_open, inet_addr, isascii, isatty, mmap, newlocale, openat, pathconf, pthread_equal, pthread_getspecific, pthread_mutex_trylock, readdir, readlink, recvmsg, regexec, scandir, semget, setjmp, shm_open, shmget, sigismember, strcasecmp, strsignal, ttyname
std::async()
. Not using the return value makes the call synchronous.std::launder()
. Not using the return value usually means that the function interface was misunderstood by the programmer. Only the returned pointer is "laundered", not the argument.clang-tidy - bugprone-virtual-near-miss
Warn if a function is a near miss (ie. the name is very similar and the function signature is the same) to a virtual function from a base class.
+Warn if a function is a near miss (i.e. the name is very similar and the function signature is the same) to a virtual function from a base class.
Example:
struct Base {
virtual void func();
};
struct Derived : Base {
- virtual funk();
+ virtual void funk();
// warning: 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it?
};
The cert-exp42-c check is an alias, please see bugprone-suspicious-memory-comparison for more information.
+The cert-flp37-c check is an alias, please see bugprone-suspicious-memory-comparison for more information.
+MemSetNames
-Specify extra functions to flag that act similarily to memset
. Specify names in a semicolon delimited list. Default is an empty string. The check will detect the following functions: memset, std::memset.
Specify extra functions to flag that act similarly to memset
. Specify names in a semicolon delimited list. Default is an empty string. The check will detect the following functions: memset, std::memset.
MemCpyNames
-Specify extra functions to flag that act similarily to memcpy
. Specify names in a semicolon delimited list. Default is an empty string. The check will detect the following functions: std::memcpy, memcpy, std::memmove, memmove, std::strcpy, strcpy, memccpy, stpncpy, strncpy.
Specify extra functions to flag that act similarly to memcpy
. Specify names in a semicolon delimited list. Default is an empty string. The check will detect the following functions: std::memcpy, memcpy, std::memmove, memmove, std::strcpy, strcpy, memccpy, stpncpy, strncpy.
MemCmpNames
-Specify extra functions to flag that act similarily to memcmp
. Specify names in a semicolon delimited list. Default is an empty string. The check will detect the following functions: std::memcmp, memcmp, std::strcmp, strcmp, strncmp.
Specify extra functions to flag that act similarly to memcmp
. Specify names in a semicolon delimited list. Default is an empty string. The check will detect the following functions: std::memcmp, memcmp, std::strcmp, strcmp, strncmp.
This check corresponds to the CERT C++ Coding Standard rule OOP57-CPP. Prefer special member functions and overloaded operators to C Standard Library functions.
clang-tidy - cppcoreguidelines-init-variables
Checks whether there are local variables that are declared without an initial value. These may lead to unexpected behaviour if there is a code path that reads the variable before assigning to it.
+Checks whether there are local variables that are declared without an initial value. These may lead to unexpected behavior if there is a code path that reads the variable before assigning to it.
Only integers, booleans, floats, doubles and pointers are checked. The fix option initializes all detected values with the value of zero. An exception is float and double types, which are initialized to NaN.
As an example a function that looks like this:
void function() {
@@ -5671,6 +5949,17 @@ void function() {
// Rest of the function.
}
+It warns for the uninitialized enum case, but without a FixIt:
+enum A {A1, A2, A3};
+enum A_c : char { A_c1, A_c2, A_c3 };
+enum class B { B1, B2, B3 };
+enum class B_i : int { B_i1, B_i2, B_i3 };
+void function() {
+ A a; // Warning: variable 'a' is not initialized
+ A_c a_c; // Warning: variable 'a_c' is not initialized
+ B b; // Warning: variable 'b' is not initialized
+ B_i b_i; // Warning: variable 'b_i' is not initialized
+}
IncludeStyle
@@ -5750,7 +6039,7 @@ void function() {char
to unsigned char
),char
to unsigned char
) if WarnOnIntegerNarrowingConversion Option is set,uint64_t
to float
),double
to int
),double
to float
) if WarnOnFloatingPointNarrowingConversion Option is set.WarnOnIntegerNarrowingConversion
+When true, the check will warn on narrowing integer conversion (e.g. int
to size_t
). true by default.
WarnOnFloatingPointNarrowingConversion
When true, the check will warn on narrowing floating point conversion (e.g. double
to float
). true by default.
WarnWithinTemplateInstantiation
+When true, the check will warn on narrowing conversions within template instantiations. false by default.
+WarnOnEquivalentBitWidth
+When true, the check will warn on narrowing conversions that arise from casting between types of equivalent bit width. (e.g. int n = uint(0); or long long n = double(0);) true by default.
+IgnoreConversionFromTypes
+Narrowing conversions from any type in this semicolon-separated list will be ignored. This may be useful to weed out commonly occurring, but less commonly problematic assignments such as int n = std::vector<char>().size(); or int n = std::difference(it1, it2);. The default list is empty, but one suggested list for a legacy codebase would be size_t;ptrdiff_t;size_type;difference_type.
+PedanticMode
When true, the check will warn on assigning a floating point constant to an integer value even if the floating point value is exactly representable in the destination type (e.g. int i = 1.0;
). false by default.
AllowMissingMoveFunctionsWhenCopyIsDeleted
-When set to true (default is false), this check doesn't flag classes which define deleted copy operations but don't define move operations. This flags is related to Google C++ Style Guide https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types. With this option enabled, the following class won't be flagged:
+When set to true (default is false), this check doesn't flag classes which define deleted copy operations but don't define move operations. This flag is related to Google C++ Style Guide https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types. With this option enabled, the following class won't be flagged:
struct A {
A(const A&) = delete;
A& operator=(const A&) = delete;
@@ -6320,6 +6625,47 @@ use(d); // Slice.
clang-tidy - cppcoreguidelines-virtual-class-destructor
+Finds virtual classes whose destructor is neither public and virtual nor protected and non-virtual. A virtual class's destructor should be specified in one of these ways to prevent undefined behavior.
+This check implements C.35 from the CppCoreGuidelines.
+Note that this check will diagnose a class with a virtual method regardless of whether the class is used as a base class or not.
+Fixes are available for user-declared and implicit destructors that are either public and non-virtual or protected and virtual. No fixes are offered for private destructors. There, the decision whether to make them private and virtual or protected and non-virtual depends on the use case and is thus left to the user.
+For example, the following classes/structs get flagged by the check since they violate guideline C.35:
+struct Foo { // NOK, protected destructor should not be virtual
+ virtual void f();
+protected:
+ virtual ~Foo(){}
+};
+class Bar { // NOK, public destructor should be virtual
+ virtual void f();
+public:
+ ~Bar(){}
+};
+This would be rewritten to look like this:
+struct Foo { // OK, destructor is not virtual anymore
+ virtual void f();
+protected:
+ ~Foo(){}
+};
+class Bar { // OK, destructor is now virtual
+ virtual void f();
+public:
+ virtual ~Bar(){}
+};
+For better consistency of user code, the check renames both virtual and non-virtual member functions with matching names in derived types. The check tries to provide a only warning when a fix cannot be made safely, as is the case with some template and macro uses.
+For better consistency of user code, the check renames both virtual and non-virtual member functions with matching names in derived types. The check tries to provide only a warning when a fix cannot be made safely, as is the case with some template and macro uses.
Check for assembler statements. No fix is offered.
-Inline assembler is forbidden by the High Intergrity C++ Coding Standard as it restricts the portability of code.
+Inline assembler is forbidden by the High Integrity C++ Coding Standard as it restricts the portability of code.
clang-tidy - hicpp-signed-bitwise
Finds uses of bitwise operations on signed integer types, which may lead to undefined or implementation defined behaviour.
+Finds uses of bitwise operations on signed integer types, which may lead to undefined or implementation defined behavior.
The according rule is defined in the High Integrity C++ Standard, Section 5.6.1.
cert-dcl03-c redirects here as an alias for this check.
-Replaces assert()
with static_assert()
if the condition is evaluatable at compile time.
Replaces assert()
with static_assert()
if the condition is evaluable at compile time.
The condition of static_assert()
is evaluated at compile time which is safer and more efficient.
char
, wchar_t
, unicode character types) will not be flagged to allow catching sting literals.throw;
it happens often enough in real code.throw;
it happens often enough in real code.std::unique_ptr<Foo> x, y;
x.reset(y.release()); -> x = std::move(y);
If y
is already rvalue, std::move()
is not added. x
and y
can also be std::unique_ptr<Foo>*
.
IncludeStyle
+A string specifying which include-style is used, llvm or google. Default is llvm.
+which will not compile, since the lambda does not contain an operator()
that that accepts 2 arguments. With permissive parameter list, it instead generates
which will not compile, since the lambda does not contain an operator()
that accepts 2 arguments. With permissive parameter list, it instead generates
int add(int x, int y) { return x + y; }
int foo() {
std::function<int(int,int)> ignore_args = [](auto&&...) { return add(2, 2); }
@@ -8732,7 +9083,7 @@ for (auto & elem : v)
MakeReverseRangeFunction
-Specify the function used to reverse an iterator pair, the function should accept a class with rbegin
and rend
methods and return a class with begin
and end
methods methods that call the rbegin
and rend
methods respectively. Common examples are ranges::reverse_view
and llvm::reverse
. Default value is an empty string.
+Specify the function used to reverse an iterator pair, the function should accept a class with rbegin
and rend
methods and return a class with begin
and end
methods that call the rbegin
and rend
methods respectively. Common examples are ranges::reverse_view
and llvm::reverse
. Default value is an empty string.
MakeReverseRangeHeader
@@ -8743,7 +9094,7 @@ for (auto & elem : v)
A string specifying which include-style is used, llvm or google. Default is llvm.
Limitations
-There are certain situations where the tool may erroneously perform transformations that remove information and change semantics. Users of the tool should be aware of the behaviour and limitations of the check outlined by the cases below.
+There are certain situations where the tool may erroneously perform transformations that remove information and change semantics. Users of the tool should be aware of the behavior and limitations of the check outlined by the cases below.
Comments inside loop headers
Comments inside the original loop header are ignored and deleted when transformed.
for (int i = 0; i < N; /* This will be deleted */ ++i) { }
@@ -8813,7 +9164,7 @@ for (vector<int>::iterator it = vec.begin(), e = vec.end(); it != e; ++it)
}
}
As range-based for loops are only available since OpenMP 5, this check should not been used on code with a compatibility requirements of OpenMP prior to version 5. It is intentional that this check does not make any attempts to exclude incorrect diagnostics on OpenMP for loops prior to OpenMP 5.
+As range-based for loops are only available since OpenMP 5, this check should not be used on code with a compatibility requirement of OpenMP prior to version 5. It is intentional that this check does not make any attempts to exclude incorrect diagnostics on OpenMP for loops prior to OpenMP 5.
To prevent this check to be applied (and to break) OpenMP for loops but still be applied to non-OpenMP for loops the usage of NOLINT
(see clang-tidy-nolint
) on the specific for loops is recommended.
For more information about the pass-by-value idiom, read: Want Speed? Pass by Value.
+For more information about the pass-by-value idiom, read: Want Speed? Pass by Value.
Finds macro expansions of DISALLOW_COPY_AND_ASSIGN(Type)
and replaces them with a deleted copy constructor and a deleted assignment operator.
Before the delete
keyword was introduced in C++11 it was common practice to declare a copy constructor and an assignment operator as a private members. This effectively makes them unusable to the public API of a class.
Before the delete
keyword was introduced in C++11 it was common practice to declare a copy constructor and an assignment operator as private members. This effectively makes them unusable to the public API of a class.
With the advent of the delete
keyword in C++11 we can abandon the private
access of the copy constructor and the assignment operator and delete the methods entirely.
When running this check on a code like this:
class Foo {
@@ -9360,7 +9711,7 @@ for (auto I = my_container.begin(), E = my_container.end(); I != E; ++I) {
}
The check will only replace iterator type-specifiers when all of the following conditions are satisfied:
std
namespace:
+std
namespace:
array
deque
auto
would cause the type of the variable to be deduced as std::initializer_list
.Frequently, when a pointer is declared and initialized with new
, the pointee type is written twice: in the declaration type and in the new
expression. In this cases, the declaration type can be replaced with auto
improving readability and maintainability.
Frequently, when a pointer is declared and initialized with new
, the pointee type is written twice: in the declaration type and in the new
expression. In this case, the declaration type can be replaced with auto
improving readability and maintainability.
TypeName *my_pointer = new TypeName(my_param);
// becomes
@@ -9425,7 +9776,7 @@ auto *my_pointer = new TypeName(my_param);
auto *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
Frequently, when a variable is declared and initialized with a cast, the variable type is written twice: in the declaration type and in the cast expression. In this cases, the declaration type can be replaced with auto
improving readability and maintainability.
Frequently, when a variable is declared and initialized with a cast, the variable type is written twice: in the declaration type and in the cast expression. In this case, the declaration type can be replaced with auto
improving readability and maintainability.
TypeName *my_pointer = static_cast<TypeName>(my_param);
// becomes
@@ -9552,7 +9903,7 @@ struct A {
Options
UseAssignment
-If this option is set to true (default is false), the check will initialise members with an assignment. For example:
+If this option is set to true (default is false), the check will initialize members with an assignment. For example:
struct A {
A() {}
@@ -9782,8 +10133,8 @@ private:
bool empty() const;
bool empty(int i) const;
transforms to:
-[[nodiscard] bool empty() const;
-[[nodiscard] bool empty(int i) const;
+[[nodiscard]] bool empty() const;
+[[nodiscard]] bool empty(int i) const;
Options
ReplacementString
@@ -9878,7 +10229,7 @@ struct bar {
clang-tidy - modernize-use-nullptr
modernize-use-nullptr
-The check converts the usage of null pointer constants (eg. NULL
, 0
) to use the new C++11 nullptr
keyword.
+The check converts the usage of null pointer constants (e.g. NULL
, 0
) to use the new C++11 nullptr
keyword.
Example
void assignment() {
char *a = NULL;
@@ -10292,7 +10643,7 @@ MPI_Send(&buf, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
clang-tidy - objc-nsinvocation-argument-lifetime
objc-nsinvocation-argument-lifetime
-Finds calls to NSInvocation
methods under ARC that don't have proper argument object lifetimes. 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 to incorrect releasing behavior if the object pointers are not declared __unsafe_unretained
.
+Finds calls to NSInvocation
methods under ARC that don't have proper argument object lifetimes. 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
.
For code:
id arg;
[invocation getArgument:&arg atIndex:2];
@@ -10365,7 +10716,7 @@ __unsafe_unretained id returnValue;
openmp-exception-escape
Analyzes OpenMP Structured Blocks and checks that no exception escapes out of the Structured Block it was thrown in.
-As per the OpenMP specification, a structured block is an executable statement, possibly compound, with a single entry at the top and a single exit at the bottom. Which means, throw
may not be used to to 'exit' out of the structured block. If an exception is not caught in the same structured block it was thrown in, the behaviour is undefined.
+As per the OpenMP specification, a structured block is an executable statement, possibly compound, with a single entry at the top and a single exit at the bottom. Which means, throw
may not be used to 'exit' out of the structured block. If an exception is not caught in the same structured block it was thrown in, the behavior is undefined.
FIXME: this check does not model SEH, setjmp
/longjmp
.
WARNING! This check may be expensive on large source files.
Options
@@ -10488,7 +10839,7 @@ str.find('A');
AllowedTypes
-A semicolon-separated list of names of types allowed to be copied in each iteration. Regular expressions are accepted, e.g. [Rr]ef(erence)?$ matches every type with suffix Ref, ref, Reference and reference. The default is empty.
+A semicolon-separated list of names of types allowed to be copied in each iteration. Regular expressions are accepted, e.g. [Rr]ef(erence)?$ matches every type with suffix Ref, ref, Reference and reference. The default is empty. If a name in the list contains the sequence :: it is matched against the qualified typename (i.e. namespace::Type, otherwise it is matched against only the type name (i.e. Type).
References
]]>
@@ -10555,7 +10906,7 @@ for (const pair<int, vector<string>>& p : my_map) {}
performance-inefficient-algorithm
Warns on inefficient use of STL algorithms on associative containers.
-Associative containers implements some of the algorithms as methods which should be preferred to the algorithms in the algorithm header. The methods can take advantage of the order of the elements.
+Associative containers implement some of the algorithms as methods which should be preferred to the algorithms in the algorithm header. The methods can take advantage of the order of the elements.
std::set<int> s;
auto it = std::find(s.begin(), s.end(), 43);
@@ -10859,7 +11210,7 @@ A::~A() = default;
performance-type-promotion-in-math-fn
Finds calls to C math library functions (from math.h
or, in C++, cmath
) with implicit float
to double
promotions.
-For example, warns on ::sin(0.f)
, because this funciton's parameter is a double. You probably meant to call std::sin(0.f)
(in C++), or sinf(0.f)
(in C).
+For example, warns on ::sin(0.f)
, because this function's parameter is a double. You probably meant to call std::sin(0.f)
(in C++), or sinf(0.f)
(in C).
float a;
asin(a);
@@ -10907,7 +11258,11 @@ void Function(const Foo& foo) {
Options
AllowedTypes
-A semicolon-separated list of names of types allowed to be initialized by copying. Regular expressions are accepted, e.g. [Rr]ef(erence)?$ matches every type with suffix Ref, ref, Reference and reference. The default is empty.
+A semicolon-separated list of names of types allowed to be initialized by copying. Regular expressions are accepted, e.g. [Rr]ef(erence)?$ matches every type with suffix Ref, ref, Reference and reference. The default is empty. If a name in the list contains the sequence :: it is matched against the qualified typename (i.e. namespace::Type, otherwise it is matched against only the type name (i.e. Type).
+
+
+ExcludedContainerTypes
+A semicolon-separated list of names of types whose methods are allowed to return the const reference the variable is copied from. When an expensive to copy variable is copy initialized by the return value from a type on this list the check does not trigger. This can be used to exclude types known to be const incorrect or where the lifetime or immutability of returned references is not tied to mutations of the container. An example are view types that don't own the underlying data. Like for AllowedTypes above, regular expressions are accepted and the inclusion of :: determines whether the qualified typename is matched or not.
References
]]>
@@ -10960,7 +11315,7 @@ void setValue(string Value) {
AllowedTypes
-A semicolon-separated list of names of types allowed to be passed by value. Regular expressions are accepted, e.g. [Rr]ef(erence)?$ matches every type with suffix Ref, ref, Reference and reference. The default is empty.
+A semicolon-separated list of names of types allowed to be passed by value. Regular expressions are accepted, e.g. [Rr]ef(erence)?$ matches every type with suffix Ref, ref, Reference and reference. The default is empty. If a name in the list contains the sequence :: it is matched against the qualified typename (i.e. namespace::Type, otherwise it is matched against only the type name (i.e. Type).
References
]]>
@@ -11158,6 +11513,22 @@ bool empty() const;
INFO
CODE_SMELL
clang-tidy - readability-data-pointer
+ +Finds cases where code could use data()
rather than the address of the element at index 0 in a container. 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.
This also ensures that in the case that the container is empty, the data pointer access does not perform an errant memory access.
+WarnOnConditionVariables
-When true, the check will attempt to refactor a variable defined inside the condition of the if
statement that is used in the else
branch defining them just before the if
statement. This can only be done if the if
statement is the last statement in its parents scope. Default value is true.
When true, the check will attempt to refactor a variable defined inside the condition of the if
statement that is used in the else
branch defining them just before the if
statement. This can only be done if the if
statement is the last statement in its parent's scope. Default value is true.
There is an alias of this check called llvm-else-after-return. In that version the options WarnOnUnfixable
and WarnOnConditionVariables
are both set to false by default.
DescribeBasicIncrements
If set to true, then for each function exceeding the complexity threshold the check will issue additional diagnostics on every piece of code (loop, if statement, etc.) which contributes to that complexity. See also the examples below. Default is true.
+IgnoreMacros
+If set to true, the check will ignore code inside macros. Note, that also any macro arguments are ignored, even if they should count to the complexity. As this might change in the future, this option isn't guaranteed to be forward-compatible. Default is false.
+There are three basic building blocks of a Cognitive Complexity metric:
While by itself the nesting level not change the function's Cognitive Complexity metric, it is tracked, and is used by the next, third building block. The following structures increase the nesting level (by 1):
+While by itself the nesting level does not change the function's Cognitive Complexity metric, it is tracked, and is used by the next, third building block. The following structures increase the nesting level (by 1):
Conditional operators:
@@ -11432,6 +11807,93 @@ if (p)LINEAR 5min
clang-tidy - readability-identifier-length
+ +This check finds variables and function parameters whose length are too short. The desired name length is configurable.
+Special cases are supported for loop counters and for exception variable names.
+The following options are described below:
++++
+- +
MinimumVariableNameLength
,IgnoredVariableNames
- +
MinimumParameterNameLength
,IgnoredParameterNames
- +
MinimumLoopCounterNameLength
,IgnoredLoopCounterNames
- +
MinimumExceptionNameLength
,IgnoredExceptionVariableNames
MinimumVariableNameLength
+All variables (other than loop counter, exception names and function parameters) are expected to have at least a length of MinimumVariableNameLength (default is 3). Setting it to 0 or 1 disables the check entirely.
+int doubler(int x) // warns that x is too short
+{
+ return 2 * x;
+}
+This check does not have any fix suggestions in the general case since variable names have semantic value.
+IgnoredVariableNames
+Specifies a regular expression for variable names that are to be ignored. The default value is empty, thus no names are ignored.
+MinimumParameterNameLength
+All function parameter names are expected to have a length of at least MinimumParameterNameLength (default is 3). Setting it to 0 or 1 disables the check entirely.
+int i = 42; // warns that 'i' is too short
+This check does not have any fix suggestions in the general case since variable names have semantic value.
+IgnoredParameterNames
+Specifies a regular expression for parameters that are to be ignored. The default value is ^[n]$ for historical reasons.
+MinimumLoopCounterNameLength
+Loop counter variables are expected to have a length of at least MinimumLoopCounterNameLength characters (default is 2). Setting it to 0 or 1 disables the check entirely.
+// This warns that 'q' is too short.
+for (int q = 0; q < size; ++ q) {
+ // ...
+}
+IgnoredLoopCounterNames
+Specifies a regular expression for counter names that are to be ignored. The default value is ^[ijk_]$; the first three symbols for historical reasons and the last one since it is frequently used as a "don't care" value, specifically in tools such as Google Benchmark.
+// This does not warn by default, for historical reasons.
+for (int i = 0; i < size; ++ i) {
+ // ...
+}
+MinimumExceptionNameLength
+Exception clause variables are expected to have a length of at least MinimumExceptionNameLength (default is 2). Setting it to 0 or 1 disables the check entirely.
+try {
+ // ...
+}
+// This warns that 'e' is too short.
+catch (const std::exception& x) {
+ // ...
+}
+IgnoredExceptionVariableNames
+Specifies a regular expression for exception variable names that are to be ignored. The default value is ^[e]$ mainly for historical reasons.
+try {
+ // ...
+}
+// This does not warn by default, for historical reasons.
+catch (const std::exception& e) {
+ // ...
+}
+Many configuration options are available, in order to be able to create different rules for different kinds of identifiers. In general, the rules are falling back to a more generic rule if the specific case is not configured.
The naming of virtual methods is reported where they occur in the base class, but not where they are overridden, as it can't be fixed locally there. This also applies for pseudo-override patterns like CRTP.
The following options are describe below:
+The following options are described below:
@@ -11533,12 +11995,17 @@ if (p)-
- +
AbstractClassCase
,AbstractClassPrefix
,AbstractClassSuffix
,AbstractClassIgnoredRegexp
AbstractClassCase
,AbstractClassPrefix
,AbstractClassSuffix
,AbstractClassIgnoredRegexp
,AbstractClassHungarianPrefix
- -
AggressiveDependentMemberLookup
- -
ClassCase
,ClassPrefix
,ClassSuffix
,ClassIgnoredRegexp
- -
ClassConstantCase
,ClassConstantPrefix
,ClassConstantSuffix
,ClassConstantIgnoredRegexp
- +
ClassMemberCase
,ClassMemberPrefix
,ClassMemberSuffix
,ClassMemberIgnoredRegexp
- +
ClassCase
,ClassPrefix
,ClassSuffix
,ClassIgnoredRegexp
,ClassHungarianPrefix
- +
ClassConstantCase
,ClassConstantPrefix
,ClassConstantSuffix
,ClassConstantIgnoredRegexp
,ClassConstantHungarianPrefix
ClassMemberCase
,ClassMemberPrefix
,ClassMemberSuffix
,ClassMemberIgnoredRegexp
,ClassMemberHungarianPrefix
- -
ClassMethodCase
,ClassMethodPrefix
,ClassMethodSuffix
,ClassMethodIgnoredRegexp
- -
ConstantCase
,ConstantPrefix
,ConstantSuffix
,ConstantIgnoredRegexp
- -
ConstantMemberCase
,ConstantMemberPrefix
,ConstantMemberSuffix
,ConstantMemberIgnoredRegexp
- -
ConstantParameterCase
,ConstantParameterPrefix
,ConstantParameterSuffix
,ConstantParameterIgnoredRegexp
- +
ConstantPointerParameterCase
,ConstantPointerParameterPrefix
,ConstantPointerParameterSuffix
,ConstantPointerParameterIgnoredRegexp
- +
ConstantCase
,ConstantPrefix
,ConstantSuffix
,ConstantIgnoredRegexp
,ConstantHungarianPrefix
- +
ConstantMemberCase
,ConstantMemberPrefix
,ConstantMemberSuffix
,ConstantMemberIgnoredRegexp
,ConstantMemberHungarianPrefix
- +
ConstantParameterCase
,ConstantParameterPrefix
,ConstantParameterSuffix
,ConstantParameterIgnoredRegexp
,ConstantParameterHungarianPrefix
ConstantPointerParameterCase
,ConstantPointerParameterPrefix
,ConstantPointerParameterSuffix
,ConstantPointerParameterIgnoredRegexp
,ConstantPointerParameterHungarianPrefix
ConstexprFunctionCase
,ConstexprFunctionPrefix
,ConstexprFunctionSuffix
,ConstexprFunctionIgnoredRegexp
- -
ConstexprMethodCase
,ConstexprMethodPrefix
,ConstexprMethodSuffix
,ConstexprMethodIgnoredRegexp
- +
ConstexprVariableCase
,ConstexprVariablePrefix
,ConstexprVariableSuffix
,ConstexprVariableIgnoredRegexp
ConstexprVariableCase
,ConstexprVariablePrefix
,ConstexprVariableSuffix
,ConstexprVariableIgnoredRegexp
,ConstexprVariableHungarianPrefix
- -
EnumCase
,EnumPrefix
,EnumSuffix
,EnumIgnoredRegexp
- +
EnumConstantCase
,EnumConstantPrefix
,EnumConstantSuffix
,EnumConstantIgnoredRegexp
EnumConstantCase
,EnumConstantPrefix
,EnumConstantSuffix
,EnumConstantIgnoredRegexp
,EnumConstantHungarianPrefix
FunctionCase
,FunctionPrefix
,FunctionSuffix
,FunctionIgnoredRegexp
- -
GetConfigPerFile
- -
GlobalConstantCase
,GlobalConstantPrefix
,GlobalConstantSuffix
,GlobalConstantIgnoredRegexp
- +
GlobalConstantPointerCase
,GlobalConstantPointerPrefix
,GlobalConstantPointerSuffix
,GlobalConstantPointerIgnoredRegexp
- +
GlobalConstantCase
,GlobalConstantPrefix
,GlobalConstantSuffix
,GlobalConstantIgnoredRegexp
,GlobalConstantHungarianPrefix
GlobalConstantPointerCase
,GlobalConstantPointerPrefix
,GlobalConstantPointerSuffix
,GlobalConstantPointerIgnoredRegexp
,GlobalConstantPointerHungarianPrefix
- -
GlobalFunctionCase
,GlobalFunctionPrefix
,GlobalFunctionSuffix
,GlobalFunctionIgnoredRegexp
- -
GlobalPointerCase
,GlobalPointerPrefix
,GlobalPointerSuffix
,GlobalPointerIgnoredRegexp
- +
GlobalVariableCase
,GlobalVariablePrefix
,GlobalVariableSuffix
,GlobalVariableIgnoredRegexp
- +
GlobalPointerCase
,GlobalPointerPrefix
,GlobalPointerSuffix
,GlobalPointerIgnoredRegexp
,GlobalPointerHungarianPrefix
GlobalVariableCase
,GlobalVariablePrefix
,GlobalVariableSuffix
,GlobalVariableIgnoredRegexp
,GlobalVariableHungarianPrefix
IgnoreMainLikeFunctions
- -
InlineNamespaceCase
,InlineNamespacePrefix
,InlineNamespaceSuffix
,InlineNamespaceIgnoredRegexp
- -
LocalConstantCase
,LocalConstantPrefix
,LocalConstantSuffix
,LocalConstantIgnoredRegexp
- -
LocalConstantPointerCase
,LocalConstantPointerPrefix
,LocalConstantPointerSuffix
,LocalConstantPointerIgnoredRegexp
- -
LocalPointerCase
,LocalPointerPrefix
,LocalPointerSuffix
,LocalPointerIgnoredRegexp
- +
LocalVariableCase
,LocalVariablePrefix
,LocalVariableSuffix
,LocalVariableIgnoredRegexp
- +
LocalConstantCase
,LocalConstantPrefix
,LocalConstantSuffix
,LocalConstantIgnoredRegexp
,LocalConstantHungarianPrefix
- +
LocalConstantPointerCase
,LocalConstantPointerPrefix
,LocalConstantPointerSuffix
,LocalConstantPointerIgnoredRegexp
,LocalConstantPointerHungarianPrefix
- +
LocalPointerCase
,LocalPointerPrefix
,LocalPointerSuffix
,LocalPointerIgnoredRegexp
,LocalPointerHungarianPrefix
LocalVariableCase
,LocalVariablePrefix
,LocalVariableSuffix
,LocalVariableIgnoredRegexp
,LocalVariableHungarianPrefix
- -
MacroDefinitionCase
,MacroDefinitionPrefix
,MacroDefinitionSuffix
,MacroDefinitionIgnoredRegexp
- +
MemberCase
,MemberPrefix
,MemberSuffix
,MemberIgnoredRegexp
MemberCase
,MemberPrefix
,MemberSuffix
,MemberIgnoredRegexp
,MemberHungarianPrefix
MethodCase
,MethodPrefix
,MethodSuffix
,MethodIgnoredRegexp
- -
NamespaceCase
,NamespacePrefix
,NamespaceSuffix
,NamespaceIgnoredRegexp
- +
ParameterCase
,ParameterPrefix
,ParameterSuffix
,ParameterIgnoredRegexp
ParameterCase
,ParameterPrefix
,ParameterSuffix
,ParameterIgnoredRegexp
,ParameterHungarianPrefix
- -
ParameterPackCase
,ParameterPackPrefix
,ParameterPackSuffix
,ParameterPackIgnoredRegexp
- -
PointerParameterCase
,PointerParameterPrefix
,PointerParameterSuffix
,PointerParameterIgnoredRegexp
- +
PrivateMemberCase
,PrivateMemberPrefix
,PrivateMemberSuffix
,PrivateMemberIgnoredRegexp
- +
PointerParameterCase
,PointerParameterPrefix
,PointerParameterSuffix
,PointerParameterIgnoredRegexp
,PointerParameterHungarianPrefix
PrivateMemberCase
,PrivateMemberPrefix
,PrivateMemberSuffix
,PrivateMemberIgnoredRegexp
,PrivateMemberHungarianPrefix
- -
PrivateMethodCase
,PrivateMethodPrefix
,PrivateMethodSuffix
,PrivateMethodIgnoredRegexp
- +
ProtectedMemberCase
,ProtectedMemberPrefix
,ProtectedMemberSuffix
,ProtectedMemberIgnoredRegexp
ProtectedMemberCase
,ProtectedMemberPrefix
,ProtectedMemberSuffix
,ProtectedMemberIgnoredRegexp
,ProtectedMemberHungarianPrefix
- -
ProtectedMethodCase
,ProtectedMethodPrefix
,ProtectedMethodSuffix
,ProtectedMethodIgnoredRegexp
- +
PublicMemberCase
,PublicMemberPrefix
,PublicMemberSuffix
,PublicMemberIgnoredRegexp
PublicMemberCase
,PublicMemberPrefix
,PublicMemberSuffix
,PublicMemberIgnoredRegexp
,PublicMemberHungarianPrefix
PublicMethodCase
,PublicMethodPrefix
,PublicMethodSuffix
,PublicMethodIgnoredRegexp
- -
ScopedEnumConstantCase
,ScopedEnumConstantPrefix
,ScopedEnumConstantSuffix
,ScopedEnumConstantIgnoredRegexp
- -
StaticConstantCase
,StaticConstantPrefix
,StaticConstantSuffix
,StaticConstantIgnoredRegexp
- +
StaticVariableCase
,StaticVariablePrefix
,StaticVariableSuffix
,StaticVariableIgnoredRegexp
- +
StaticConstantCase
,StaticConstantPrefix
,StaticConstantSuffix
,StaticConstantIgnoredRegexp
,StaticConstantHungarianPrefix
StaticVariableCase
,StaticVariablePrefix
,StaticVariableSuffix
,StaticVariableIgnoredRegexp
,StaticVariableHungarianPrefix
StructCase
,StructPrefix
,StructSuffix
,StructIgnoredRegexp
TemplateParameterCase
,TemplateParameterPrefix
,TemplateParameterSuffix
,TemplateParameterIgnoredRegexp
- @@ -11513,7 +11975,7 @@ if (p)
TemplateTemplateParameterCase
,TemplateTemplateParameterPrefix
,TemplateTemplateParameterSuffix
,TemplateTemplateParameterIgnoredRegexp
TypeTemplateParameterCase
,TypeTemplateParameterPrefix
,TypeTemplateParameterSuffix
,TypeTemplateParameterIgnoredRegexp
UnionCase
,UnionPrefix
,UnionSuffix
,UnionIgnoredRegexp
- -
ValueTemplateParameterCase
,ValueTemplateParameterPrefix
,ValueTemplateParameterSuffix
,ValueTemplateParameterIgnoredRegexp
- +
VariableCase
,VariablePrefix
,VariableSuffix
,VariableIgnoredRegexp
VariableCase
,VariablePrefix
,VariableSuffix
,VariableIgnoredRegexp
,VariableHungarianPrefix
VirtualMethodCase
,VirtualMethodPrefix
,VirtualMethodSuffix
,VirtualMethodIgnoredRegexp
AbstractClassSuffix
When defined, the check will ensure abstract class names will add the suffix with the given value (regardless of casing).
+AbstractClassHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- AbstractClassCase of
lower_case
- AbstractClassPrefix of
pre_
- AbstractClassSuffix of
+_post
- AbstractClassHungarianPrefix of
On
Identifies and/or transforms abstract class names as follows:
@@ -11614,12 +12081,17 @@ struct Derived : Base<T> {ClassSuffix
When defined, the check will ensure class names will add the suffix with the given value (regardless of casing).
+ClassHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ClassCase of
lower_case
- ClassPrefix of
pre_
- ClassSuffix of
+_post
- ClassHungarianPrefix of
On
Identifies and/or transforms class names as follows:
@@ -11651,12 +12123,17 @@ public:ClassConstantSuffix
When defined, the check will ensure class constant names will add the suffix with the given value (regardless of casing).
+ClassConstantHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ClassConstantCase of
lower_case
- ClassConstantPrefix of
pre_
- ClassConstantSuffix of
+_post
- ClassConstantHungarianPrefix of
On
Identifies and/or transforms class constant names as follows:
@@ -11686,12 +12163,17 @@ public:ClassMemberSuffix
When defined, the check will ensure class member names will add the suffix with the given value (regardless of casing).
+ClassMemberHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ClassMemberCase of
lower_case
- ClassMemberPrefix of
pre_
- ClassMemberSuffix of
+_post
- ClassMemberHungarianPrefix of
On
Identifies and/or transforms class member names as follows:
@@ -11756,12 +12238,17 @@ public:ConstantSuffix
When defined, the check will ensure constant names will add the suffix with the given value (regardless of casing).
+ConstantHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ConstantCase of
lower_case
- ConstantPrefix of
pre_
- ConstantSuffix of
+_post
- ConstantHungarianPrefix of
On
Identifies and/or transforms constant names as follows:
@@ -11785,12 +12272,17 @@ public:ConstantMemberSuffix
When defined, the check will ensure constant member names will add the suffix with the given value (regardless of casing).
+ConstantMemberHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ConstantMemberCase of
lower_case
- ConstantMemberPrefix of
pre_
- ConstantMemberSuffix of
+_post
- ConstantMemberHungarianPrefix of
On
Identifies and/or transforms constant member names as follows:
@@ -11818,12 +12310,17 @@ public:ConstantParameterSuffix
When defined, the check will ensure constant parameter names will add the suffix with the given value (regardless of casing).
+ConstantParameterHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ConstantParameterCase of
lower_case
- ConstantParameterPrefix of
pre_
- ConstantParameterSuffix of
+_post
- ConstantParameterHungarianPrefix of
On
Identifies and/or transforms constant parameter names as follows:
@@ -11847,12 +12344,17 @@ public:ConstantPointerParameterSuffix
When defined, the check will ensure constant pointer parameter names will add the suffix with the given value (regardless of casing).
+ConstantPointerParameterHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ConstantPointerParameterCase of
lower_case
- ConstantPointerParameterPrefix of
pre_
- ConstantPointerParameterSuffix of
+_post
- ConstantPointerParameterHungarianPrefix of
On
Identifies and/or transforms constant pointer parameter names as follows:
@@ -11940,12 +12442,17 @@ public:ConstexprVariableSuffix
When defined, the check will ensure constexpr variable names will add the suffix with the given value (regardless of casing).
+ConstexprVariableHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ConstexprVariableCase of
lower_case
- ConstexprVariablePrefix of
pre_
- ConstexprVariableSuffix of
+_post
- ConstexprVariableHungarianPrefix of
On
Identifies and/or transforms constexpr variable names as follows:
@@ -11998,12 +12505,17 @@ public:EnumConstantSuffix
When defined, the check will ensure enumeration constant names will add the suffix with the given value (regardless of casing).
+EnumConstantHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- EnumConstantCase of
lower_case
- EnumConstantPrefix of
pre_
- EnumConstantSuffix of
+_post
- EnumConstantHungarianPrefix of
On
Identifies and/or transforms enumeration constant names as follows:
@@ -12060,12 +12572,17 @@ public:GlobalConstantSuffix
When defined, the check will ensure global constant names will add the suffix with the given value (regardless of casing).
+GlobalConstantHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- GlobalConstantCase of
lower_case
- GlobalConstantPrefix of
pre_
- GlobalConstantSuffix of
+_post
- GlobalConstantHungarianPrefix of
On
Identifies and/or transforms global constant names as follows:
@@ -12089,12 +12606,17 @@ public:GlobalConstantPointerSuffix
When defined, the check will ensure global constant pointer names will add the suffix with the given value (regardless of casing).
+GlobalConstantPointerHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- GlobalConstantPointerCase of
lower_case
- GlobalConstantPointerPrefix of
pre_
- GlobalConstantPointerSuffix of
+_post
- GlobalConstantPointerHungarianPrefix of
On
Identifies and/or transforms global constant pointer names as follows:
@@ -12147,12 +12669,17 @@ public:GlobalPointerSuffix
When defined, the check will ensure global pointer names will add the suffix with the given value (regardless of casing).
+GlobalPointerHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- GlobalPointerCase of
lower_case
- GlobalPointerPrefix of
pre_
- GlobalPointerSuffix of
+_post
- GlobalPointerHungarianPrefix of
On
Identifies and/or transforms global pointer names as follows:
@@ -12176,12 +12703,17 @@ public:GlobalVariableSuffix
When defined, the check will ensure global variable names will add the suffix with the given value (regardless of casing).
+GlobalVariableHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- GlobalVariableCase of
lower_case
- GlobalVariablePrefix of
pre_
- GlobalVariableSuffix of
+_post
- GlobalVariableHungarianPrefix of
On
Identifies and/or transforms global variable names as follows:
@@ -12246,12 +12778,17 @@ inline namespace pre_inlinenamespace_post {LocalConstantSuffix
When defined, the check will ensure local constant names will add the suffix with the given value (regardless of casing).
+LocalConstantHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- LocalConstantCase of
lower_case
- LocalConstantPrefix of
pre_
- LocalConstantSuffix of
+_post
- LocalConstantHungarianPrefix of
On
Identifies and/or transforms local constant names as follows:
@@ -12275,12 +12812,17 @@ inline namespace pre_inlinenamespace_post {LocalConstantPointerSuffix
When defined, the check will ensure local constant pointer names will add the suffix with the given value (regardless of casing).
+LocalConstantPointerHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- LocalConstantPointerCase of
lower_case
- LocalConstantPointerPrefix of
pre_
- LocalConstantPointerSuffix of
+_post
- LocalConstantPointerHungarianPrefix of
On
Identifies and/or transforms local constant pointer names as follows:
@@ -12304,12 +12846,17 @@ inline namespace pre_inlinenamespace_post {LocalPointerSuffix
When defined, the check will ensure local pointer names will add the suffix with the given value (regardless of casing).
+LocalPointerHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- LocalPointerCase of
lower_case
- LocalPointerPrefix of
pre_
- LocalPointerSuffix of
+_post
- LocalPointerHungarianPrefix of
On
Identifies and/or transforms local pointer names as follows:
@@ -12341,12 +12888,17 @@ inline namespace pre_inlinenamespace_post {LocalVariableSuffix
When defined, the check will ensure local variable names will add the suffix with the given value (regardless of casing).
+LocalVariableHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- LocalVariableCase of
lower_case
- LocalVariablePrefix of
pre_
- LocalVariableSuffix of
+_post
- LocalVariableHungarianPrefix of
On
Identifies and/or transforms local variable names as follows:
@@ -12400,12 +12952,17 @@ inline namespace pre_inlinenamespace_post {MemberSuffix
When defined, the check will ensure member names will add the suffix with the given value (regardless of casing).
+MemberHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- MemberCase of
lower_case
- MemberPrefix of
pre_
- MemberSuffix of
+_post
- MemberHungarianPrefix of
On
Identifies and/or transforms member names as follows:
@@ -12499,12 +13056,17 @@ inline namespace pre_inlinenamespace_post {ParameterSuffix
When defined, the check will ensure parameter names will add the suffix with the given value (regardless of casing).
+ParameterHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ParameterCase of
lower_case
- ParameterPrefix of
pre_
- ParameterSuffix of
+_post
- ParameterHungarianPrefix of
On
Identifies and/or transforms parameter names as follows:
@@ -12561,12 +13123,17 @@ inline namespace pre_inlinenamespace_post {PointerParameterSuffix
When defined, the check will ensure pointer parameter names will add the suffix with the given value (regardless of casing).
+PointerParameterHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- PointerParameterCase of
lower_case
- PointerParameterPrefix of
pre_
- PointerParameterSuffix of
+_post
- PointerParameterHungarianPrefix of
On
Identifies and/or transforms pointer parameter names as follows:
@@ -12590,12 +13157,17 @@ inline namespace pre_inlinenamespace_post {PrivateMemberSuffix
When defined, the check will ensure private member names will add the suffix with the given value (regardless of casing).
+PrivateMemberHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- PrivateMemberCase of
lower_case
- PrivateMemberPrefix of
pre_
- PrivateMemberSuffix of
+_post
- PrivateMemberHungarianPrefix of
On
Identifies and/or transforms private member names as follows:
@@ -12660,12 +13232,17 @@ private:ProtectedMemberSuffix
When defined, the check will ensure protected member names will add the suffix with the given value (regardless of casing).
+ProtectedMemberHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ProtectedMemberCase of
lower_case
- ProtectedMemberPrefix of
pre_
- ProtectedMemberSuffix of
+_post
- ProtectedMemberHungarianPrefix of
On
Identifies and/or transforms protected member names as follows:
@@ -12730,12 +13307,17 @@ protected:PublicMemberSuffix
When defined, the check will ensure public member names will add the suffix with the given value (regardless of casing).
+PublicMemberHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- PublicMemberCase of
lower_case
- PublicMemberPrefix of
pre_
- PublicMemberSuffix of
+_post
- PublicMemberHungarianPrefix of
On
Identifies and/or transforms public member names as follows:
@@ -12800,12 +13382,17 @@ public:ScopedEnumConstantSuffix
When defined, the check will ensure scoped enum constant names will add the suffix with the given value (regardless of casing).
+ScopedEnumConstantHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- ScopedEnumConstantCase of
lower_case
- ScopedEnumConstantPrefix of
pre_
- ScopedEnumConstantSuffix of
+_post
- ScopedEnumConstantHungarianPrefix of
On
Identifies and/or transforms enumeration constant names as follows:
@@ -12829,12 +13416,17 @@ public:StaticConstantSuffix
When defined, the check will ensure static constant names will add the suffix with the given value (regardless of casing).
+StaticConstantHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- StaticConstantCase of
lower_case
- StaticConstantPrefix of
pre_
- StaticConstantSuffix of
+_post
- StaticConstantHungarianPrefix of
On
Identifies and/or transforms static constant names as follows:
@@ -12858,12 +13450,17 @@ public:StaticVariableSuffix
When defined, the check will ensure static variable names will add the suffix with the given value (regardless of casing).
+StaticVariableHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- StaticVariableCase of
lower_case
- StaticVariablePrefix of
pre_
- StaticVariableSuffix of
+_post
- StaticVariableHungarianPrefix of
On
Identifies and/or transforms static variable names as follows:
@@ -13137,12 +13734,17 @@ public:VariableSuffix
When defined, the check will ensure variable names will add the suffix with the given value (regardless of casing).
+VariableHungarianPrefix
+When enabled, the check ensures that the declared identifier will have a Hungarian notation prefix based on the declared type.
+For example using values of:
- VariableCase of
lower_case
- VariablePrefix of
pre_
- VariableSuffix of
+_post
- VariableHungarianPrefix of
On
Identifies and/or transforms variable names as follows:
@@ -13185,8 +13787,274 @@ public: public: virtual int pre_member_function_post(); } -In Hungarian notation, a variable name starts with a group of lower-case letters which are mnemonics for the type or purpose of that variable, followed by whatever name the programmer has chosen; this last part is sometimes distinguished as the given name. The first character of the given name can be capitalized to separate it from the type indicators (see also CamelCase). Otherwise the case of this character denotes scope.
+The following table is the default mapping table of Hungarian Notation which maps Decl to its prefix string. You can also have your own style in config file.
+Primitive Types | +Microsoft data types | +
---|---|
+ |
+Type Prefix | +
================= ============== ====================== ============== | +=========== ============== | +
int8_t i8 signed int si | +BOOL b | +
int16_t i16 signed short ss | +BOOLEAN b | +
int32_t i32 signed short int ssi | +BYTE by | +
int64_t i64 signed long long int slli | +CHAR c | +
uint8_t u8 signed long long sll | +UCHAR uc | +
uint16_t u16 signed long int sli | +SHORT s | +
uint32_t u32 signed long sl | +USHORT us | +
uint64_t u64 signed s | +WORD w | +
char8_t c8 unsigned long long int ulli | +DWORD dw | +
char16_t c16 unsigned long long ull | +DWORD32 dw32 | +
char32_t c32 unsigned long int uli | +DWORD64 dw64 | +
float f unsigned long ul | +LONG l | +
double d unsigned short int usi | +ULONG ul | +
char c unsigned short us | +ULONG32 ul32 | +
bool b unsigned int ui | +ULONG64 ul64 | +
_Bool b unsigned u | +ULONGLONG ull | +
int i long long int lli | +HANDLE h | +
size_t n long double ld | +INT i | +
short s long long ll | +INT8 i8 | +
signed i long int li | +INT16 i16 | +
unsigned u long l | +INT32 i32 | +
long l ptrdiff_t p | +INT64 i64 | +
long long ll | +UINT ui | +
unsigned long ul | +UINT8 u8 | +
long double ld | +UINT16 u16 | +
ptrdiff_t p | +UINT32 u32 | +
wchar_t wc | +UINT64 u64 | +
short int si short s |
+PVOID p |
+
There are more trivial options for Hungarian Notation:
+Options are not belonging to any specific Decl.
+Options for NULL-terminated string.
+Options for derived types.
+Options for primitive types.
+Options for user-defined types.
+HungarianNotation.General.TreatStructAsClass
HungarianNotation.DerivedType.Array
HungarianNotation.DerivedType.Pointer
HungarianNotation.DerivedType.FunctionPointer
HungarianNotation.CString.CharPrinter
HungarianNotation.CString.CharArray
HungarianNotation.CString.WideCharPrinter
HungarianNotation.CString.WideCharArray
HungarianNotation.PrimitiveType.*
HungarianNotation.UserDefinedType.*
HungarianNotation.General.TreatStructAsClass
+When defined, the check will treat naming of struct as a class. The default value is false.
+HungarianNotation.DerivedType.Array
+When defined, the check will ensure variable name will add the prefix with the given string. The default prefix is a.
+HungarianNotation.DerivedType.Pointer
+When defined, the check will ensure variable name will add the prefix with the given string. The default prefix is p.
+HungarianNotation.DerivedType.FunctionPointer
+When defined, the check will ensure variable name will add the prefix with the given string. The default prefix is fn.
+Before:
+// Array
+int DataArray[2] = {0};
+// Pointer
+void *DataBuffer = NULL;
+// FunctionPointer
+typedef void (*FUNC_PTR)();
+FUNC_PTR FuncPtr = NULL;
+After:
+// Array
+int aDataArray[2] = {0};
+// Pointer
+void *pDataBuffer = NULL;
+// FunctionPointer
+typedef void (*FUNC_PTR)();
+FUNC_PTR fnFuncPtr = NULL;
+HungarianNotation.CString.CharPrinter
+When defined, the check will ensure variable name will add the prefix with the given string. The default prefix is sz.
+HungarianNotation.CString.CharArray
+When defined, the check will ensure variable name will add the prefix with the given string. The default prefix is sz.
+HungarianNotation.CString.WideCharPrinter
+When defined, the check will ensure variable name will add the prefix with the given string. The default prefix is wsz.
+HungarianNotation.CString.WideCharArray
+When defined, the check will ensure variable name will add the prefix with the given string. The default prefix is wsz.
+Before:
+// CharPrinter
+const char *NamePtr = "Name";
+// CharArray
+const char NameArray[] = "Name";
+// WideCharPrinter
+const wchar_t *WideNamePtr = L"Name";
+// WideCharArray
+const wchar_t WideNameArray[] = L"Name";
+After:
+// CharPrinter
+const char *szNamePtr = "Name";
+// CharArray
+const char szNameArray[] = "Name";
+// WideCharPrinter
+const wchar_t *wszWideNamePtr = L"Name";
+// WideCharArray
+const wchar_t wszWideNameArray[] = L"Name";
+HungarianNotation.PrimitiveType.*
+When defined, the check will ensure variable name of involved primitive types will add the prefix with the given string. The default prefixes are defined in the default mapping table.
+HungarianNotation.UserDefinedType.*
+When defined, the check will ensure variable name of involved primitive types will add the prefix with the given string. The default prefixes are defined in the default mapping table.
+Before:
+int8_t ValueI8 = 0;
+int16_t ValueI16 = 0;
+int32_t ValueI32 = 0;
+int64_t ValueI64 = 0;
+uint8_t ValueU8 = 0;
+uint16_t ValueU16 = 0;
+uint32_t ValueU32 = 0;
+uint64_t ValueU64 = 0;
+float ValueFloat = 0.0;
+double ValueDouble = 0.0;
+ULONG ValueUlong = 0;
+DWORD ValueDword = 0;
+After:
+int8_t i8ValueI8 = 0;
+int16_t i16ValueI16 = 0;
+int32_t i32ValueI32 = 0;
+int64_t i64ValueI64 = 0;
+uint8_t u8ValueU8 = 0;
+uint16_t u16ValueU16 = 0;
+uint32_t u32ValueU32 = 0;
+uint64_t u64ValueU64 = 0;
+float fValueFloat = 0.0;
+double dValueDouble = 0.0;
+ULONG ulValueUlong = 0;
+DWORD dwValueDword = 0;
+Many coding guidelines advise replacing the magic values with symbolic constants to improve readability. Here are a few references:
-
- Rule ES.45: Avoid 'magic constants'; use symbolic constants in C++ Core Guidelines
+- Rule ES.45: Avoid "magic constants"; use symbolic constants in C++ Core Guidelines
- Rule 5.1.1 Use symbolic names instead of literal values in code in High Integrity C++
- Item 17 in "C++ Coding Standards: 101 Rules, Guidelines and Best Practices" by Herb Sutter and Andrei Alexandrescu
- Chapter 17 in "Clean Code - A handbook of agile software craftsmanship." by Robert C. Martin
@@ -13849,7 +14717,7 @@ void f() { extern int X;becomes
-extern int X;
Such redundant declarations can be removed without changing program behaviour. They can for instance be unintentional left overs from previous refactorings when code has been moved around. Having redundant declarations could in worst case mean that there are typos in the code that cause bugs.
+Such redundant declarations can be removed without changing program behavior. They can for instance be unintentional left overs from previous refactorings when code has been moved around. Having redundant declarations could in worst case mean that there are typos in the code that cause bugs.
Normally the code can be automatically fixed,
clang-tidy
can remove the second declaration. However there are 2 cases when you need to fix the code manually:
- When the declarations are in different header files;
@@ -13913,7 +14781,7 @@ private:IgnoreBaseInCopyConstructors
Default is false.
-When true, the check will ignore unnecessary base class initializations within copy constructors, since some compilers issue warnings/errors when base classes are not explicitly intialized in copy constructors. For example,
+gcc
with-Wextra
or-Werror=extra
issues warning or errorbase class 'Bar' should be explicitly initialized in the copy constructor
ifBar()
were removed in the following example:When true, the check will ignore unnecessary base class initializations within copy constructors, since some compilers issue warnings/errors when base classes are not explicitly initialized in copy constructors. For example,
gcc
with-Wextra
or-Werror=extra
issues warning or errorbase class 'Bar' should be explicitly initialized in the copy constructor
ifBar()
were removed in the following example:-// Explicitly initializing member s and base class Bar is unnecessary. struct Foo : public Bar { @@ -14335,13 +15203,132 @@ if (0 != str1.compare(str2)) { // Use str1 == "foo" instead. if (str1.compare("foo") == 0) { }
The above code examples shows the list of if-statements that this check will give a warning for. All of them uses
+compare
to check if equality or inequality of two strings instead of using the correct operators.The above code examples show the list of if-statements that this check will give a warning for. All of them uses
compare
to check if equality or inequality of two strings instead of using the correct operators.References
]]>INFO CODE_SMELL
clang-tidy - readability-suspicious-call-argument
+ +Finds function calls where the arguments passed are provided out of order, based on the difference between the argument name and the parameter names of the function.
+Given a function call f(foo, bar);
and a function signature void f(T tvar, U uvar)
, the arguments foo
and bar
are swapped if foo
(the argument name) is more similar to uvar
(the other parameter) than tvar
(the parameter it is currently passed to) and bar
is more similar to tvar
than uvar
.
Warnings might indicate either that the arguments are swapped, or that the names' cross-similarity might hinder code comprehension.
+The following heuristics are implemented in the check. If any of the enabled heuristics deem the arguments to be provided out of order, a warning will be issued.
+The heuristics themselves are implemented by considering pairs of strings, and are symmetric, so in the following there is no distinction on which string is the argument name and which string is the parameter name.
+The most trivial heuristic, which compares the two strings for case-insensitive equality.
+Common abbreviations can be specified which will deem the strings similar if the abbreviated and the abbreviation stand together. For example, if src
is registered as an abbreviation for source
, then the following code example will be warned about.
void foo(int source, int x);
+foo(b, src);
+The abbreviations to recognise can be configured with the Abbreviations<opt_Abbreviations>
check option. This heuristic is case-insensitive.
The prefix heuristic reports if one of the strings is a sufficiently long prefix of the other string, e.g. target
to targetPtr
. The similarity percentage is the length ratio of the prefix to the longer string, in the previous example, it would be 6 / 9 = 66.66...%.
This heuristic can be configured with bounds<opt_Bounds>
. The default bounds are: below 25% dissimilar and above 30% similar. This heuristic is case-insensitive.
Analogous to the Prefix heuristic. In the case of oldValue
and value
compared, the similarity percentage is 8 / 5 = 62.5%.
This heuristic can be configured with bounds<opt_Bounds>
. The default bounds are: below 25% dissimilar and above 30% similar. This heuristic is case-insensitive.
The substring heuristic combines the prefix and the suffix heuristic, and tries to find the longest common substring in the two strings provided. The similarity percentage is the ratio of the found longest common substring against the longer of the two input strings. For example, given val
and rvalue
, the similarity is 3 / 6 = 50%. If no characters are common in the two string, 0%.
This heuristic can be configured with bounds<opt_Bounds>
. The default bounds are: below 40% dissimilar and above 50% similar. This heuristic is case-insensitive.
The Levenshtein distance describes how many single-character changes (additions, changes, or removals) must be applied to transform one string into another.
+The Levenshtein distance is translated into a similarity percentage by dividing it with the length of the longer string, and taking its complement with regards to 100%. For example, given something
and anything
, the distance is 4 edits, and the similarity percentage is 100% - 4 / 9 = 55.55...%.
This heuristic can be configured with bounds<opt_Bounds>
. The default bounds are: below 50% dissimilar and above 66% similar. This heuristic is case-sensitive.
The Jaro-Winkler distance is an edit distance like the Levenshtein distance. It is calculated from the amount of common characters that are sufficiently close to each other in position, and to-be-changed characters. The original definition of Jaro has been extended by Winkler to weigh prefix similarities more. The similarity percentage is expressed as an average of the common and non-common characters against the length of both strings.
+This heuristic can be configured with bounds<opt_Bounds>
. The default bounds are: below 75% dissimilar and above 85% similar. This heuristic is case-insensitive.
The Sorensen-Dice coefficient was originally defined to measure the similarity of two sets. Formally, the coefficient is calculated by dividing 2 * #(intersection) with #(set1) + #(set2), where #() is the cardinality function of sets. This metric is applied to strings by creating bigrams (substring sequences of length 2) of the two strings and using the set of bigrams for the two strings as the two sets.
+This heuristic can be configured with bounds<opt_Bounds>
. The default bounds are: below 60% dissimilar and above 70% similar. This heuristic is case-insensitive.
MinimumIdentifierNameLength
+Sets the minimum required length the argument and parameter names need to have. Names shorter than this length will be ignored. Defaults to 3.
+Abbreviations
+For the Abbreviation heuristic (see here<abbreviation_heuristic>
), this option configures the abbreviations in the "abbreviation=abbreviated_value" format. The option is a string, with each value joined by ";".
By default, the following abbreviations are set:
++++
+- addr=address
+- arr=array
+- attr=attribute
+- buf=buffer
+- cl=client
+- cnt=count
+- col=column
+- cpy=copy
+- dest=destination
+- dist=distance
+- dst=distance
+- elem=element
+- hght=height
+- i=index
+- idx=index
+- len=length
+- ln=line
+- lst=list
+- nr=number
+- num=number
+- pos=position
+- ptr=pointer
+- ref=reference
+- src=source
+- srv=server
+- stmt=statement
+- str=string
+- val=value
+- var=variable
+- vec=vector
+- wdth=width
+
The configuration options for each implemented heuristic (see above) is constructed dynamically. In the following, <HeuristicName> refers to one of the keys from the heuristics implemented.
+<HeuristicName>
+True or False, whether a particular heuristic, such as Equality or Levenshtein is enabled.
+Defaults to True for every heuristic.
+<HeuristicName>DissimilarBelow, <HeuristicName>SimilarAbove
+A value between 0 and 100, expressing a percentage. The bounds set what percentage of similarity the heuristic must deduce for the two identifiers to be considered similar or dissimilar by the check.
+Given arguments arg1
and arg2
passed to param1
and param2
, respectively, the bounds check is performed in the following way: If the similarity of the currently passed argument order (arg1
to param1
) is below the DissimilarBelow threshold, and the similarity of the suggested swapped order (arg1
to param2
) is above the SimilarAbove threshold, the swap is reported.
For the defaults of each heuristic, see above<heuristics>
.
When comparing the argument names and parameter names, the following logic is used to gather the names for comparison:
+Parameter names are the identifiers as written in the source code.
+Argument names are:
++++
+- If a variable is passed, the variable's name.
+- If a subsequent function call's return value is used as argument, the called function's name.
+- Otherwise, empty string.
+
Empty argument or parameter names are ignored by the heuristics.
+CheckId
of your custom rule, a title, a description, and a default severity.