[[noreturn]] function pointer

When I use clang ( version 3.4 (trunk 194574) ) to compile this:

 typedef void (* FunctionThatNeverReturns [[ noreturn ]])(); 

I get this:

 error: 'noreturn' attribute only applies to functions and methods 

This surprises me because it did a great job with the old version of clang.

So how can I define a pointer to the [[ noreturn ]] function?

I need this because I call the function pointer inside the [[ noreturn ]] function, which explicitly gives a warning if the function pointer is not marked as noreturn.

Oh and it works:

 typedef void (* FunctionThatNeverReturns [[ gnu::noreturn ]])(); 

But is there a compiler-independent solution?

+6
source share
1 answer

try it

 typedef void (* FunctionThatNeverReturns)() [[ noreturn ]]; 

In your original, the specifier is placed so that it applies to the pointer, and not to the specified object. But the noreturn pointer does not make sense at all, you are trying to type a pointer to the noreturn function.

Demo: http://ideone.com/9mBR9x

0
source

Source: https://habr.com/ru/post/958156/


All Articles