| Issue |
173147
|
| Summary |
clang-tidy: google-readability-casting, aka modernize-avoid-c-style-cast, for nullptr
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
e-kwsm
|
```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<int *>( )
```
<https://godbolt.org/z/6bW1hY981>
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs