C++ Logo

std-proposals

Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Tue, 10 Jun 2025 09:55:17 -0400
On Tue, Jun 10, 2025 at 1:29 AM Nikl Kelbon via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Im not about noexcept(auto), im about implicit noexcept autodetect if noexcept specifier not exist on move constructor, move assign operator and lambdas.
>
> It already works for = default special member functions

That's because the compiler generates the code for you, and that code
is very simple. It's always an ordered sequence of one particular
operation on all subobjects: default initialization, copy, move, etc.

What you're asking for requires the compiler to look over arbitrary
user-provided code.

Ignoring what I would consider the conceptual misuse of `noexcept`,
the fact that it's just on these specific functions and has no syntax
to ask for it feels... extremely odd. We gave lambdas the ability to
detect return types in C++11, but that led to C++14's generalized
return type autodetection. If it's useful for lambdas, then it's
useful for general functions.

This might have had a leg to stand on if it were just move functions
(though even then, I would find it dubious). But once you throw
lambdas into the mix, it's really hard to justify not being able to do
it everywhere. Which then means it needs to have a syntax.

Received on 2025-06-10 13:55:29