C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Floating an idea: [[no_address]] for functions.

From: Jan Schultke <janschultke_at_[hidden]>
Date: Mon, 24 Mar 2025 06:32:59 +0100
I like the idea in principle, but a proposal would have to figure out
many nuanced issues.

Firstly, attributes are ignorable, and perhaps, we would want a
program to be straight up ill-formed if it takes the address of a
function we've marked as non-addressable. I don't see a compelling
reason to keep this an attribute. Rather, a contextual keyword like
the following makes sense:

> void f() no_address;

Secondly, we would presumably want to add this attribute or keyword to
existing standard library functions that are non-addressable. How much
code would that break or affect in practice? In theory, taking the
address of standard library functions is not supported, but all
compilers permit it anyway, and there is no warning for it either. It
would be very weird if we didn't add this to standard library
functions, but if we did, we'd also need to know what impact that has
in practice.

Thirdly, how does this interact with lambdas? Could this be used to
disallow converting lambdas to function pointers?

Anyhow, I like the idea, but it's harder to standardize than it looks.

Received on 2025-03-24 05:33:13