This fixes some mess I left in .clang-tidy (#43863) when clang-tidy
build times were too bad and had to be reduced urgently.
Verified locally that runtime isn't affected by this PR.
clang-tidy now also checks code in header files. Because the analyzer
finds tons of issues, activate the check only for directory "base/" (see
file ".clang-tidy"). All other directories, in particular "src/" are
left to future work.
While many findings were fixed, some were not (and suppressed instead).
Reasons for this include: a) the file is 1:1 copypaste of a 3rd-party
lib (e.g. pcg_extras.h) and fixing stuff would make upgrades/fixes more
difficult b) a fix would have broken lots of using code
readability-identifier-length was added with Clang 14 which does not yet
run in the central builds yet but (at least on my system) locally.
Disabling the check because it is too noisy. Older clang-tidy versions
will just ignore the setting.
Enable:
- bugprone-lambda-function-name: "Checks for attempts to get the name of
a function from within a lambda expression. The name of a lambda is
always something like operator(), which is almost never what was
intended."
- bugprone-unhandled-self-assignment: "Finds user-defined copy
assignment operators which do not protect the code against
self-assignment either by checking self-assignment explicitly or using
the copy-and-swap or the copy-and-move method.""
- hicpp-invalid-access-moved: "Warns if an object is used after it has
been moved."
- hicpp-use-noexcept: "This check replaces deprecated dynamic exception
specifications with the appropriate noexcept specification (introduced
in C++11)"
- hicpp-use-override: "Adds override (introduced in C++11) to overridden
virtual functions and removes virtual from those functions as it is
not required."
- 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."
Split up:
- cppcoreguidelines-*. Some of them may be useful (haven't checked in
detail), therefore allow to toggle them individually.
Disable:
- linuxkernel-*. Obvious.
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.