I recently learned about the [[noreturn]]
attribute and wanted to try and implement it on one of my existing code snippets.
I added the attribute to a void return type function with no return;
keyword on it whatsoever. However, I'm getting this error:
[ 17%] Building CXX object CMakeFiles/Renderer.dir/src/opengl/text_render.cpp.o
/home/turgut/Desktop/CppProjects/videoo-render/src/opengl/text_render.cpp:7:25: error: function ‘const void OpenGL::Text::set_background(int, int, float, int, int, int, int, float, std::string*)’ declared ‘[[noreturn]]’ but its first declaration was not
7 | [[noreturn]] const void Text::set_background(
|
make[2]: *** [CMakeFiles/Renderer.dir/build.make:132: CMakeFiles/Renderer.dir/src/opengl/text_render.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:277: CMakeFiles/Renderer.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
I'm using c++ 20+ so I don't think there is a problem with versions.
What is wrong with my usage of [[noreturn]]
and how should I use it propperly? Am I missing a piece of knowledge about it?
Here is the function in question:
[[noreturn]] void Text::set_background(
int x, int y, float z,
int w, int h,
int gw, int gh,
float ang, std::string* hex_color
){
background = new Background(x-w, y-h);
background->color = (*hex_color).c_str();
background->bg_texture = new Texture(
x - 10, (1000 - y) + 10, w, -h ,gw, gh
);
background->bg_texture->init(ang, z, nullptr);
}
I've also tried to use it on some other similar functions but got a similar result.