[cfe-dev] K&R style argument lists and the type system

Eli Friedman eli.friedman at gmail.com
Tue Aug 26 11:07:53 PDT 2008

On Mon, Aug 25, 2008 at 10:36 PM, Chris Lattner <clattner at apple.com> wrote:
> On Aug 25, 2008, at 5:50 PM, Eli Friedman wrote:
>> On Mon, Aug 25, 2008 at 4:20 PM, steve naroff <snaroff at apple.com> wrote:
>>>> Any ideas for how to solve this?  We could always map definitions
>>>> identifier-lists to FunctionTypeNoProto, but that means a good chunk
>>>> of additional code to check type-merging doesn't do bad stuff to a
>>>> definition and allow CodeGen to synthesize the type of such a function
>>>> definition properly.
>>> This makes more sense to me, since there is no prototype for a(x,y).
>>> I think it's better to keep the old style function definition separate
>>> from
>>> the modern syntax/semantics...
>> Bleh, I think we have to encode the exact signature into the type
>> system somehow.  Consider the following testcase:
>> int a(x) float x; {return x;}
>> int b(int x) {return x;}
>> int c(int x) {return (x ? a : b)(1);}
>> This is a constraint violation per C99, which would be completely
>> unintuitive to diagnose without encoding the fact that "a" takes float
>> into the type.
>> gcc apparently screws up this case; it doesn't print a warning even
>> with -std=c99 -pedantic.  Although, the standard is a bit screwy here.
> Are you sure this is a constraint violation?  Of what rule?

"For two function types to be compatible [...] If one type has a
parameter type list and the other type is specified by a function
definition that contains a (possibly empty) identifier list, both
shall agree in the number of parameters, and the type of each
prototype parameter shall be compatible with the type that results
from the application of the default argument promotions to the type of
the corresponding identifier."


More information about the cfe-dev mailing list