According to stack overflow, The [[noreturn]]
attribute specifies that a function does not return. Ok, thats fine.
But I don't understand how to use [[noreturn]]
attribute in program. I tried to use [[noreturn]]
attribute in my code. But when I compiled my code in GCC compiler, I got following error.
error: expected unqualified-id before ‘[’ token
[[noreturn]] void f(int i) {
^
cp1.cpp: In function ‘int main()’:
cp1.cpp:11:6: error: ‘f’ was not declared in this scope
f(10);
My code is here:
#include <cstdlib>
[[noreturn]] void f(int i) {
if (i > 0)
throw "Received positive input";
std::exit(0);
}
int main()
{
f(10);
}
How to use [[noreturn]]
attribute in C++?