C++ Logo

std-proposals

Advanced search

Re: [std-proposals] auto-noexcept for move and lambdas

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Mon, 9 Jun 2025 20:36:50 +0300
On 9 Jun 2025 18:20, Andre Kostur via Std-Proposals wrote:
> Food for thought: there may be a silent performance degradation if
> such a constructor were to "accidentally" get a noexcept(false)
> function call somewhere. Or some member variable (or
> member-of-a-member, etc) loses its noexcept(true) status.

Losing performance would be better than silently introducing a code path
that ends with std::terminate(). Also, you can test that your function
marked as noexcept(auto) remains noexcept(true) in tests, but you can't
test that your function marked as noexcept(true) doesn't actually call
std::terminate if something within it becomes potentially throwing.

> On Mon, Jun 9, 2025 at 7:33 AM Nikl Kelbon via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>>
>> It would be nice to add automatic noexpect detection, if it is not explicitly set, for the move constructor, move assign operator and for lambdas
>> Use cases: move constructor not marked as noexcept is performance bug
>>
>> Typical scope exit implementations checks noexcept function or not in destructor, it may force them to make useless actions or make scope_exit not std::destructible (throw constructor)
>>
>> How ?
>>
>> Just check every expression in lambda / move constructor / move assign if it may throw by current C++ rules and noexcept == 9noexcpt(exprs) || ...)
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-06-09 17:36:53