This compiles without any warnings.
Is this legal in C and C++ or does it just work in gcc and clang?
If it is legal, is it some new thing after C99?
This code is allowed in C++
but not allowed in C
From Return statement @ cppreference
In a function returning void, the return statement with expression can be used, if the expression type is void.
OTOH in C11 specs draft n1570:
Major changes in the second edition included:
return without expression not permitted in function that returns a value (and vice versa)
(return
with expression not permitted in function that returns a void
)
and 6.8.6.4 return
A return statement with an expression shall not appear in a function whose return type is void. A return statement without an expression shall only appear in a function whose return type is void.
(even if the expression evaluates to void
)