C++ Logo


Advanced search

Re: Need your input on waring when we use 'using' clause and [[noreturn]]

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Thu, 21 Apr 2022 16:16:49 +0200
On 21/04/2022 14:32, Vivek Pandey via Std-Discussion wrote:
> Please let us know how we can use 'using' clause to declare a function
> pointer to a function that does not return, so that this warning does
> not show up.
> When we can create aliases for normal function pointers with 'using'
> then why does it give warning "warning: function declared 'noreturn'
> should not return [-Winvalid-noreturn]" for a function declared as
> [[noreturn]].
> Any solution that can resolve it? Can this be part of C++ standards?

Currently there is no way to mark things such as pointers to functions
as [[noreturn]] (meaning something like "this pointer points to a
function that does not return").

There is also no way of doing so using any other stdlib facility such as
std::function. I suspect that a proper solution would require making
[[noreturn]] part of the type system, which sounds undesirable.

The easiest solution *by far* is to add a std::unreachable() call at the
end of CallIDontReturn(), since that's what you mean.

Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Received on 2022-04-21 14:16:53