[clang] [clang] Add diagnostic for usage of implicit constructor with pointer to bool convertion (PR #143990)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 15 10:05:55 PDT 2025


================
@@ -4397,6 +4397,9 @@ def ext_ms_impcast_fn_obj : ExtWarn<
   "implicit conversion between pointer-to-function and pointer-to-object is a "
   "Microsoft extension">, InGroup<MicrosoftCast>;
 
+def warn_imp_constructor_pointer_to_bool : Warning<
+    "implicit conversion from %0 to %1 calls %q2; did you intend to dereference ?">,
----------------
AaronBallman wrote:

```suggestion
    "implicit conversion from %0 to %1 calls %q2; did you intend to dereference instead?">,
```
@erichkeane do you think we should have fixits attached to notes? Something like:

`implicit conversion from %0 to %1 calls %q2` -- warning on the code
`did you intend to dereference?` -- with fixit to insert `*`
`did you intend the bool conversion?` -- with fixit to insert a (`static_`)cast or the `!!` trick

My concern is: if the user intended this behavior, it'd be nice for them to have a way to silence the diagnostic. And if they didn't intend this behavior, giving them a fix-it helps them correct their code.

https://github.com/llvm/llvm-project/pull/143990


More information about the cfe-commits mailing list