C++ Logo

std-proposals

Advanced search

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

From: Tom Honermann <tom_at_[hidden]>
Date: Sun, 10 Sep 2023 19:03:12 -0400
On 9/10/23 4:21 PM, Edward Catmur via Std-Proposals wrote:
>
>
> 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.

I think what I said is correct. A diagnostic can only be mandated for an
ill-formed program.

Tom.

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

Received on 2023-09-10 23:03:14