C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 27 Dec 2020 00:39:32 -0300
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

Received on 2020-12-26 21:39:37