C++ Logo


Advanced search

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

From: Vivek Pandey <sandesh4vivek_at_[hidden]>
Date: Thu, 21 Apr 2022 12:32:32 +0000 (UTC)

| Dear All,
Hope all of you are doing great and in the best of health.
I am here to know your input on 'waring when we use 'using' clause and [[noreturn]]'

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. As per LLVM team because of 'inline' gcc don't show up the warning

              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?

Your guidance will be of immense asset to me.
Thanking you in advance!
Vivek Pandey,
+91-7775054441 |

Received on 2022-04-21 12:32:41