C++ Logo

std-proposals

Advanced search

Re: std::as

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Mon, 26 Oct 2020 10:58:07 -0400
On Mon, Oct 26, 2020 at 10:46 AM Giuseppe D'Angelo via Std-Proposals <
std-proposals_at_[hidden]> wrote:
>
> On 26/10/2020 15:24, Arthur O'Dwyer via Std-Proposals wrote:
> >
> > Confirmed. Have people filed missed-optimization bugs against GCC and
> > MSVC on this topic, yet? People should.
> > https://godbolt.org/z/n9acqh
>
> Clang too? https://godbolt.org/z/MarcvM

That's a tougher one. Most compilers (for historical reasons) cannot assume
that references are always non-null; the caller might be testing, like,

    int main() { return &getint(v) != nullptr; }

This is UB, of course, but it's also super common in legacy code.
So what I would expect here is that the compiler vendor should provide
a *compiler
flag* something like -fno-null-references, to enable the optimization of
getint() when it returns a reference type. I haven't done my homework to
learn how that flag is spelled on any of the Big Three vendors — or even if
it exists yet.

–Arthur

Received on 2020-10-26 09:58:22