C++ Logo

std-proposals

Advanced search

Re: [std-proposals] noexcept has gotten a bit hairy -- I want a compiler error

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 06 May 2025 11:56:51 -0700
On Tuesday, 6 May 2025 02:54:32 Pacific Daylight Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> size_t bytes_needed(char const *const p) noexcept(explicit)
> {
> if ( nullptr == p ) return 0uz;
> return noexcept_cast<true>(strlen)(p) + 1uz;
> }
>
> That would be one possible use of "noexcept_cast".

Or:

    return [&]() noexcept { return strlen(p); }();

Let's not reinvent the wheel if already have a solution, albeit with a small
syntax cost. This also removes the need to capture an overload set for the
cast operator.

And you should really complain to your C library and have them add the
noexcept markers. It's QoI. glibc has the marker there for strlen, so for all
I care the problem is solved and every other implementation out there is
simply behind the state of the art.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-05-06 18:56:55