C++ Logo

std-proposals

Advanced search

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

From: Tom Honermann <tom_at_[hidden]>
Date: Sat, 9 Sep 2023 18:02:55 -0400
On 9/8/23 5:16 AM, 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.

The standard is only able to specify that a diagnostic is produced for a
ill-formed program and even then, the actual diagnostic issued is a
matter of QoI; a conforming implementation can emit "😭" as its
diagnostic. What you are effectively asking for is to make the code
above ill-formed.

Tom.

Received on 2023-09-09 22:02:57