[cfe-dev] K&R style argument lists and the type system
Chris Lattner
clattner at apple.com
Tue Aug 26 09:32:18 PDT 2008
On Aug 26, 2008, at 7:58 AM, Neil Booth wrote:
> Chris Lattner wrote:-
>
>>> 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?
>
> My front end gives
>
> "/tmp/bug.c", line 3: error: expressions of types "int (*)()" and
> "int (*)(int)" cannot be used together in a conditional expression
> int c(int x) {return (x ? a : b)(1);}
> ^
>
> Which maybe gives a clue :)
Ok, so this is simple and consistent. The type of 'a' is int().
Incidentally Neil, it is somewhat strange that you warn about types
after promotions. The "true" part of the expression has type "int()"
not "int(*)()". The user isn't using an expression of type "int(*)()"
with the conditional expression, they are using a raw function.
-Chris
More information about the cfe-dev
mailing list