C++ Logo

std-proposals

Advanced search

Re: [std-proposals] mandatory compiler diagnostic for converting function to boolean

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Mon, 11 Sep 2023 06:04:29 +0200
On 08/09/2023 11.16, Frederick Virchanza Gotham via Std-Proposals wrote:
> Today I discovered the following bug:
>
> if ( wxIsMainThread ) DoSomething();
>
> The bug here is that 'wxIsMainThread' is a function, and so it should have been:
>
> if ( wxIsMainThread() ) DoSomething();
>
> I think where we have a function converting to bool -- but not where
> we have a function pointer converting to bool -- the compiler should
> be mandated to issue a diagnostic.

We generally don't specify warnings in the standard.

Do you want to make a conversion from function to bool ill-formed,
i.e. an error?

If so, I think we need a little bit of analysis why this doesn't
break a lot of existing code (if any) that (for better or worse)
uses that conversion already.

Jens

Received on 2023-09-11 04:04:34