[cfe-dev] Unexpected error when compiling for ANSI C89

ORiordan, Martin via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 4 03:47:27 PDT 2017

Hi CFE-Devs,

When I compile the following tiny test with '-std=c89' ('clang -std=c89 -c xxx.c'):
foo(x) {
I get the following error message:
xxx.c:2:3: error: non-void function 'foo' should return a value [-Wreturn-type]
1 error generated.

But for ANSI C89, this is legal, and it is a really common pattern to have a return with no value, even though the return type is implicitly 'int', especially when K&R syntax is used:

Section The return statement, Semantics, paragraph 3
If a return statement without an expression is executed, and the value of the function call is used by the caller, the behaviour is undefined.  reaching the } that terminates a function is equivalent to executing a return statement without an expression.

Yet the following results in a warning and not an error:
foo(x) {
I get the following perfectly reasonable warning:
xxx.c:2:1: warning: control reaches end of non-void function [-Wreturn-type]
1 warning generated.

When compiling for ANSI C89, I think that the first example should also result in a warning and not an error.


Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263

This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171004/98eee03d/attachment.html>

More information about the cfe-dev mailing list