[clang-tidy] Warn on functional C-style casts
authorCarlos Galvez <carlosgalvezp@gmail.com>
Tue, 23 Nov 2021 09:27:23 +0000 (09:27 +0000)
committerCarlos Galvez <carlosgalvezp@gmail.com>
Tue, 30 Nov 2021 07:31:17 +0000 (07:31 +0000)
commit5bbe50148f3b515c170be22209395b72890f5b8c
treee81d0b4d51e9475c948e15de80a0bff65ff07cfe
parent5047e3a3ba92402b60c200201484b422cad8bea6
[clang-tidy] Warn on functional C-style casts

The google-readability-casting check is meant to be on par
with cpplint's readability/casting check, according to the
documentation. However it currently does not diagnose
functional casts, like:

float x = 1.5F;
int y = int(x);

This is detected by cpplint, however, and the guidelines
are clear that such a cast is only allowed when the type
is a class type (constructor call):

> You may use cast formats like `T(x)` only when `T` is a class type.

Therefore, update the clang-tidy check to check this
case.

Differential Revision: https://reviews.llvm.org/D114427
clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp