[cfe-users] -Winvalid-noreturn warning
David Blaikie via cfe-users
cfe-users at lists.llvm.org
Thu Jan 6 18:58:25 PST 2022
FWIW, GCC does warn on similar code - the reason it doesn't warn here is
that the function is `inline` and never called, so GCC probably never
analyses it (I pasted your code here and added a few cases to demonstrate
GCC's quirks compared to Clang's here: https://godbolt.org/z/YM9q91bx1 )
So far as I can tell, noreturn isn't carried on function types, so it isn't
possible to do what you want at the moment. That's my rough understanding,
at least.
On Thu, Jan 6, 2022 at 5:23 PM Manu agarwal via cfe-users <
cfe-users at lists.llvm.org> wrote:
> Hi,
>
> We have the below code where this warning gets generated.
>
> #include <iostream>
>
>
>
> [[noreturn]] inline void
>
> abc () noexcept
>
> {
>
> std::terminate ();
>
> }
>
>
>
> using MyNoReturn = void (*) () noexcept;
>
> //using MyNoReturn = std::add_pointer_t<decltype(abc)>; *// even this
> declaration, instead of the above, gives the same warning*
>
>
>
> [[noreturn]]
>
> inline void IDontReturn () noexcept
>
> {
>
> std::terminate ();
>
> }
>
>
> static MyNoReturn gvar {IDontReturn};
>
>
>
> [[noreturn]]
>
> inline void
>
> CallIDontReturn () noexcept
>
> {
>
> gvar (); // *here is where clang
> gives warning: function declared 'noreturn' should not return
> [-Winvalid-noreturn]*
>
> }
>
> We have the used the below command to compile:
> clang++ -std=c++17 -Wall -o runusing usingst.cpp
>
> gcc does not show this warning.
>
> Please let us know how we can use 'using' clause to declare function
> pointer to a function that does not return, so that this warning does not
> show up.
>
> Regards,
> Manu
> _______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20220106/2c0ccb0e/attachment.html>
More information about the cfe-users
mailing list