C++ Logo

std-discussion

Advanced search

noexcept(auto)?

From: Yongwei Wu <wuyongwei_at_[hidden]>
Date: Tue, 16 Apr 2024 10:43:50 +0800
I am not sure whether it is a good idea or not, or whether someone
proposed it before, but it suddenly occurred to me maybe we can use
noexcept(auto) to make the compiler analyse the function body, and
mark the function as noexcept(true) if there is nothing in the
function body that causes an exception, and as noexcept(false) if
there is a throw statement in the function body or if an non-noexcept
function is invoked.

Of course the limitation is that the function body must be available
when using the noexcept(auto) mark. With modules introduced, this
seems an even lesser concern now. Using it in a prototype declaration
is ill-formed. If the declared function prototype and the later
function definition result in different noexcept specifications, the
program is ill-formed too.

If this is feasible, maybe one day we can make noexcept(auto) the
default when the function body is provided?

-- 
Yongwei Wu
URL: http://wyw.dcweb.cn/

Received on 2024-04-16 02:44:04