C++ Logo

std-proposals

Advanced search

Re: lvalue ref-qualified this-pointers in the standard library

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Thu, 29 Jul 2021 13:26:32 +0100
Hi,

stringstream::str() changed ref-qualification (and gained a && overload) in C++20. How was that sorted out regarding ABI issues? Is the ABI issue serious?

Cheers,
Lénárd


-------- Original Message --------
From: "Gašper Ažman via Std-Proposals" <std-proposals_at_[hidden]>
Sent: July 29, 2021 12:56:54 PM GMT+01:00
To: Std-Proposals <std-proposals_at_[hidden]>
Cc: "Gašper Ažman" <gasper.azman_at_[hidden]>
Subject: Re: [std-proposals] lvalue ref-qualified this-pointers in the standard library

The short answer is that it's an ABI break. I also ref-qualify assignment
operators.

On Wed, Jul 28, 2021 at 6:04 PM Peter C++ via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> actually what you propose was in the motivation of the paper introducing
> ref-qualification of member functions.
>
> I started to teach to lvalue-ref qualify user-declared assignment
> operators.
>
> but changing the standard library and the language might be too much of a
> change with not too much of a benefit that it would be worthwhile
> attempting. (I have thought proposing it)
>
> Regards
> Peter
>
> sent from a mobile device so please excuse strange words due to
> autocorrection.
> Peter Sommerlad
> peter.cpp_at_[hidden]
> +41-79-432 23 32
>
> > On 28 Jul 2021, at 18:34, Paul Raffer via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
> >
> > 
> > Another proposal idea:
> >
> >
> > I think in most setters (and other methods that modify an object like
> operator=) in the standard library (e.g. the setters real and imag in the
> complex class) the this-pointer should be lvalue ref-qualified, so that
> temporary objects can't be modyfied.
> >
> > The signature of real should look like this
> > constexpr void real(T value) &;
> > instead of this
> > constexpr void real(T value);
> >
> >
> > In C++20 code like this
> > std::complex<double>{}.real(42.0);
> > or this
> > std::complex<double>{} = std::complex<double>{};
> > would compile, but makes no sense.
> >
> >
> > That could potentially break existing code, but only code that has bugs
> anyway. So that's a feature not a bug. Or am I wrong?
> >
> >
> > Paul
> >
> > --
> > Std-Proposals mailing list
> > Std-Proposals_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2021-07-29 07:26:42