Issue |
90794
|
Summary |
[clang] Warning-request: calling a function that converts a pointer argument to bool parameter should issue a warning
|
Labels |
clang
|
Assignees |
|
Reporter |
zhihaoy
|
In an overload set that involves `bool`, it's too easy to fall into the trap where the users are meant to pass the pointer or string literal argument to a more appropriate candidate but end up passing it to the candidate that takes `bool`. A typical case involves
```cpp
void bar(bool);
void bar(std::string);
```
Clang introduced [-Wstring-conversion](https://clang.llvm.org/docs/DiagnosticsReference.html#id877) to diagnose the case where the argument is a string literal,
```cpp
bar("");
```
but not overwise.
```cpp
bar(sz);
```
The non-literal case should also be diagnosed.
The diagnosis should also not be limited to boolean conversion from pointer to strings. Any pointers can fall into this trap:
```cpp
void foo(bool);
void foo(void *);
void test1(T *sp)
{
foo(sp); // should give a warning
}
```
If we have concerns about the situation where calling a function that takes `bool` with a pointer can appear frequently in practice, we could limit the scope to overload resolution. In other words, if overload resolution calls a candidate that converts a pointer argument to a bool parameter, Clang issues a warning, but this will be more involved.
Repro: https://godbolt.org/z/WbsMnYnW9
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs