C++ Logo

std-proposals

Advanced search

Re: Avoid copies when using string_view with APIs expecting null terminated strings

From: Nikolay Mihaylov <nmmm_at_[hidden]>
Date: Sun, 27 Dec 2020 10:34:55 +0200
... the point is...
stealing bits from pointer is not portable, even between compilers. I know
it can be done for x64 and probably Arm 64, but for Arm32 or 32 bit Intel -
I am not sure.

On Sunday, December 27, 2020, Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Saturday, 26 December 2020 19:06:25 -03 Arthur O'Dwyer wrote:
> > Storing in the pointer: almost certainly not okay, unless I have failed
> to
> > keep up with C++20 constexpr rules. string_view is specified to be
> > constexpr-friendly in C++17 and later. That means no type-punning.
>
> std::string_view is a Standard Library class. Implementations are free to
> add
> extensions that colour pointers in a constexpr fashion. In fact, they
> probably
> want to do that so that the compiler itself can keep track of what it did,
> and
> for extensions like ASan. And the good thing about colour pointers is that
> you
> don't have to remove the extra bits to dereference the data, so there's no
> casting required.
>
> One of the problems with colour pointers is that there's no convention
> (yet)
> on who gets to use which pointers. ASan would definitely like to use some
> of
> those bits, but it can't use the ones that the library uses...
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel DPG Cloud Engineering
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-12-27 02:35:04