clang-tidy: google-readability-casting, aka modernize-avoid-c-style-cast, for nullptr
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```cpp
// a.cpp
void f(int *) {}
void f(double *) {}
int main() {
f((int *)nullptr);
}
```
clang-tidy 21.1.6 warns the cast but does not provide fix:
```console
$ clang-tidy '--checks=-*,google-readability-casting' --fix a.cpp
1 warning generated.
/tmp/a.cpp:6:5: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [google-readability-casting]
5 | f((int *)nullptr);
| ^
```
However, `static_cast` is the valid choice, so it can be fixed:
```diff
--- current behaviour
+++ suggestion
-/tmp/a.cpp:6:5: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [google-readability-casting]
+/tmp/a.cpp:6:5: warning: C-style casts are discouraged; use static_cast [google-readability-casting]
5 | f((int *)nullptr);
- | ^
+ | ^~~~~~~
+ | static_cast( )
```
Contributor guide
Assessment
This issue has not been assessed yet.