[cfe-users] -Winvalid-noreturn warning

Manu agarwal via cfe-users cfe-users at lists.llvm.org
Thu Dec 23 22:23:43 PST 2021


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20211224/7c20b951/attachment.html>


More information about the cfe-users mailing list