C++ Logo

std-proposals

Advanced search

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

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Sun, 10 Sep 2023 15:21:22 -0500
On Sun, Sep 10, 2023, 11:41 Tom Honermann via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> 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.
>

Not quite true; the standard could deprecate the conversion. However,
implementations would be free to disregard that deprecation and are likely
to do so; see eg the rule of five fiasco.

-- 
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-09-10 20:21:37