serenity
serenity copied to clipboard
LibJS: Add noreturn attribute to functions that doesn't return
A few LibJS functions doesn't actually return anything which causes some compilers to error out. This commit adds the gcc noreturn attribute to them.
Most raw __attribute__
have (should be?) replaced with the macros from AK/Platform.h. Doesn't look like there's one for NORETURN
Most raw
__attribute__
have (should be?) replaced with the macros from AK/Platform.h. Doesn't look like there's one for NORETURN
Fixed 🤠
I don't like this - semantically these functions don't exist, not exist but don't return anything, so noreturn is the wrong tool. If your compiler is complaining about the lack of return statements, add some after the assertion instead.
They might not exist spec-wise. They do however exist in-code, which means that they should respect their return type (there are some other cases in LibJS where we actually return even if it's unreachable through VERIFY_NOT_REACHED
).
The reason windows based compilers complain about this is that in the windows C library, abort()
is not [[no return]] like the C++ spec says it should be. An escape hatch for your build to disable Werror or a new definition of VERIFY/VERIFY_NOT_REACHED to point to some fancy inline noretun function for those platforms might be better
As I said:
VERIFY_NOT_REACHED();
return {} / nullptr / whatever;
is a simple and acceptable solution that should work everywhere.