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?
Standard C does not support this construction:
C11 6.8.6.4: The
returnstatementConstraints
1 A
returnstatement with an expression shall not appear in a function whose return type isvoid. Areturnstatement without an expression shall only appear in a function whose return type isvoid.
No special provisions are added for the special case in the question. Some C compilers do support this as an extension (gcc does, unless instructed to conform to one of the C Standards), but C11 and previous versions consider it a constraint violation.