[cfe-dev] C90 conformance: return statements without expressions in non-void functions

Chris Lattner clattner at apple.com
Tue Sep 14 09:01:04 PDT 2010


On Sep 14, 2010, at 8:39 AM, Douglas Gregor wrote:
>> The C99 macro is defined when testing against the C99 standard and is
>> undefined for C90.
>> 
>> This code fails to compile with Clang in the C90 case:
>> 
>>> clang -S -x c -std=iso9899:1990 -o - test2.c
>> test2.c:19:5: error: non-void function 'yfunc' should return a value
>>       [-Wreturn-type]
>>     return;
>>     ^
>> 1 error generated.
>> 
>> Section 6.6.4 of C90 reads, "If a return statement without an expression
>> is executed, and the value of the function call is used by the caller,
>> the behavior is undefined." The standard says nothing (at least that
>> I've found) about the case where the value of the function is _not_
>> used, which happens to be the case for yfunc() in the context of the
>> validation suite.
>> 
>> Can any language lawyers comment on whether yfunc() should compile in
>> C90 mode?
> 
> 
> I don't know the C90 standard well, but from the statement you quote it seems that Clang is non-conformant.
> 
> That said, from a user's perspective, Clang is doing the right thing: writing a "return" statement with no expression, in a function that has a non-void return type, is asking for trouble, and we're doing users a favor by rejecting it outright. Plum Hall isn't helping anyone by checking this.

We're doing the right thing here.  That error is actually a warning that is mapped to an error.  If you want full c90 conformance, you should pass -Wno-return-type or -Wreturn-type.  However, I could be convinced that the default mapping in -std=c89 mode (but not -std=gnu89 mode) should be to warning.  If you're interested, please prepare a patch for that.  Thanks Ken,

-Chris



More information about the cfe-dev mailing list