Re: C aggregate passing (Rust kernel policy)

From: comex
Date: Sat Feb 22 2025 - 00:56:56 EST




> On Feb 21, 2025, at 2:13 PM, Bart Van Assche <bvanassche@xxxxxxx> wrote:
>
> Initially, early implementations of std::string may have used CoW or reference counting techniques.

More accurately, you can’t have one without the other. std::string is mutable, so reference counting requires copy-on-write (and of course copy-on-write wouldn’t make sense without multiple references).

> Notably, the C++11 standard explicitly banned CoW for std::string in order to avoid its pitfalls.
> [ ... ]

The C++11 spec doesn’t explicitly say ‘thou shalt not copy-on-write’, but it requires std::string's operator[] to be O(1), which effectively bans it because copying is O(n).

Which forced libstdc++ to break their ABI, since they were using copy-on-write before.