Official docs:
Some headers from C library were deprecated in C++ and are no longer
welcome in C++ codebases. Some have no effect in C++. For more details
refer to the C++ 14 Standard [depr.c.headers] section. This check
replaces C standard library headers with their C++ alternatives and
removes redundant ones.
Official docs:
Finds non-static member functions that can be made static because the
functions don’t use this. After applying modifications as suggested by
the check, running the check again might find more opportunities to
mark member functions static.
Official docs:
This check replaces deprecated dynamic exception specifications with
the appropriate noexcept specification (introduced in C++11). By
default this check will replace throw() with noexcept, and
throw(<exception>[,...]) or throw(...) with noexcept(false).
Official docs:
This check replaces default bodies of special member functions with =
default;. The explicitly defaulted function declarations enable more
opportunities in optimization, because the compiler might treat
explicitly defaulted functions as trivial.
Official docs:
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 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.
Official docs:
The check flags dereferences and non-pointer declarations of objects
that are not meant to be passed by value, such as C FILE objects or
POSIX pthread_mutex_t objects.
Official docs:
The check flags overloaded operator new() and operator delete()
functions that do not have a corresponding free store function defined
within the same scope. For instance, the check will flag a class
implementation of a non-placement operator new() when the class does
not also define a non-placement operator delete() function as well.
Official docs:
Finds non-extern non-inline function and variable definitions in
header files, which can lead to potential ODR violations in case these
headers are included from multiple translation units.
Official docs:
This check replaces default bodies of special member functions with =
default;. The explicitly defaulted function declarations enable more
opportunities in optimization, because the compiler might treat
explicitly defaulted functions as trivial.
Official docs:
Checks for usages of identifiers reserved for use by the
implementation. The C and C++ standards both reserve the following
names for such use: identifiers that begin with an underscore followed
by an uppercase letter; identifiers in the global namespace that begin
with an underscore.
Official docs:
Checks for usages of identifiers reserved for use by the
implementation. The C and C++ standards both reserve the following
names for such use: identifiers that begin with an underscore followed
by an uppercase letter; identifiers in the global namespace that begin
with an underscore.
Official docs:
Finds calls to new with missing exception handler for std::bad_alloc.
Calls to new may throw exceptions of type std::bad_alloc that should
be handled. Alternatively, the nonthrowing form of new can be used.
The check verifies that the exception is handled in the function that
calls new. If a nonthrowing version is used or the exception is
allowed to propagate out of the function no warning is generated. The
exception handler is checked if it catches a std::bad_alloc or
std::exception exception type, or all exceptions (catch-all). The
check assumes that any user-defined operator new is either noexcept or
may throw an exception of type std::bad_alloc (or one derived from
it). Other exception class types are not taken into account.
Official docs:
Finds cnd_wait, cnd_timedwait, wait, wait_for, or wait_until function
calls when the function is not invoked from a loop that checks whether
a condition predicate holds or the function has a condition parameter.
Official docs:
Finds pointers with the noescape attribute that are captured by an
asynchronously-executed block. The block arguments in dispatch_async()
and dispatch_after() are guaranteed to escape, so it is an error if a
pointer with the noescape attribute is captured by one of these
blocks.
Official docs:
This check will warn when there is a cast of a calculation result to a
bigger type. If the intention of the cast is to avoid loss of
precision then the cast is misplaced, and there can be loss of
precision. Otherwise the cast is ineffective.
Official docs:
The check looks for perfect forwarding constructors that can hide copy
or move constructors. If a non const lvalue reference is passed to the
constructor, the forwarding reference parameter will be a better match
than the const reference parameter of the copy constructor, so the
perfect forwarding constructor will be called, which can be confusing.
Official docs:
Finds instances of static variables that are dynamically initialized in
header files. This can pose problems in certain multithreaded contexts.
Official docs:
Adds pointer qualifications to auto-typed variables that are deduced to
pointers. This makes it obvious if a auto typed variable is a pointer.
This check will transform auto to auto * when the type is deduced to be
a pointer.
Official docs:
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.
Official docs:
Finds assert() with side effect. The condition of assert() is
evaluated only in debug builds so a condition with side effect can
cause different behavior in debug / release builds.
Official docs:
This check replaces the uses of the deprecated class std::auto_ptr by
std::unique_ptr (introduced in C++11). The transfer of ownership, done
by the copy-constructor and the assignment operator, is changed to
match std::unique_ptr usage by using explicit calls to std::move().
Official docs:
The check diagnoses any static_assert declaration with an empty string
literal and provides a fix-it to replace the declaration with a
single-argument static_assert declaration.
Official docs:
Correct indentation helps to understand code. Mismatch of the
syntactical structure and the indentation of the code may hide serious
problems.
Instead of disabling all checks + specifying which are enabled
(whitelist), enable all checks + specify which checks are disabled
(blacklist). The same set of checks executes as before.
Motivation:
a) Given the goal to (generally) enable as many checks as possible, a
blacklist produces a smaller and easier to maintain .clang-tidy file.
b) Many new checks introduced with LLVM 12/13/14 were forgotten to turn
on. A blacklist makes sure that future compiler upgrades enable new
checks by default.
Omitted new checks which produce too many matches or which are
controversial (e.g. readability-identifier-length).
New checks:
- misc-misleading-bidirectional + misc-misleading-identifier
Detects potential attack as described in the Trojan Source attack
- modernize-macro-to-enum
Replaces groups of adjacent macros with an unscoped anonymous enum
- modernize-shrink-to-fit
Replace copy and swap tricks on shrinkable containers with the
shrink_to_fit() method call
- modernize-use-transparent-functors
Prefer transparent functors to non-transparent ones
- modernize-use-uncaught-exceptions
This check will warn on calls to std::uncaught_exception and replace
them with calls to std::uncaught_exceptions (uncaught_exception was
deprecated with C++17)
- performance-no-int-to-ptr
Diagnoses every integer to pointer cast
- readability-duplicate-include
Looks for duplicate includes and removes them
- readability-redundant-preprocessor
Finds potentially redundant preprocessor directives
- bugprone-lambda-function-name
Checks for attempts to get the name of a function from within a lambda
expression
- bugprone-redundant-branch-condition
Finds condition variables in nested if statements that were also
checked in the outer if statement and were not changed
- bugprone-shared-ptr-array-mismatch
Finds initializations of C++ shared pointers to non-array type that
are initialized with an array
- bugprone-stringview-nullptr
Checks for various ways that the const CharT* constructor of
std::basic_string_view can be passed a null argument and replaces them
with the default constructor in most cases
- bugprone-suspicious-memory-comparison
Finds potentially incorrect calls to memcmp() based on properties of
the arguments
- not having everyone append new checks at the end means fewer merge
conflicts
- also removed check "misc-unconventional-assign-operator" which was
duplicated