C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 10 Sep 2023 15:44:45 -0700
On Friday, 8 September 2023 15:07:02 PDT Matthew Taylor via Std-Proposals
wrote:
> How confident are you that there are no legitimate use-cases for what you're
> proposing?

On some architectures, functions can be null pointers. On ELF and Apple
systems, for example, if the function is declared weak, it may have no real
implementation and the pointer will be null at runtime. This is a useful way
of detecting features at runtime. Apple uses this a lot.

However, GCC and Clang are already aware of this. They will not issue
diagnostics for weak functions converted to boolean, but will for regular
functions (by default with Clang, under -Wall for GCC). So Frederick's request
is already implemented: the compilers emit a warning.
https://gcc.godbolt.org/z/bP8PMTnxb

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-09-10 22:44:48