[cfe-commits] [Request for review] Removing redundant implicit casts in the AST
Abramo Bagnara
abramo.bagnara at gmail.com
Tue Oct 25 04:31:50 PDT 2011
Il 25/10/2011 12:36, Nicola Gigante ha scritto:
>
> Il giorno 25/ott/2011, alle ore 11:59, Abramo Bagnara ha scritto:
>>
>> This should be considered with some attention:
>>
>> void f(int (&x)[]);
>> void f(int *x);
>> void g(int *x);
>>
>> void t() {
>> int a[4];
>> f((int*)a);
>> f(a);
>> g((int*)a);
>> g(a);
>> }
>>
>> In first call to f and g I think that the ArrayToPointer should be
>> considered explicit.
>>
>
> From a source-centric point of view, maybe yes. However,
> as far as I know, an array type always immediately decays
> when used, in cases other than the argument of a sizeof()
> operator and a few others.
> If so, 'a' has already decayed to int * before the cast,
> so the cast is NoOp because it's actually useless.
No, it is not useless because it is the reason why the decay has happened.
The agreed intention is to move toward a direction where we mark as NoOp
only casts that has no effects (i.e. that can be removed without
influencing neither parsing nor execution).
A cast whose presence is the reason why the array decay to pointer is
done is not a redundant cast.
Of course the context should not be taken in consideration i.e. the
expression should be considered in isolation.
int a[4];
int *p;
p = (int*)a;
sizeof((int*)a);
Both array to pointer cast are relevant despite the fact that only in
one case the context would have generated it nevertheless.
Do you think is a sensible approach?
More information about the cfe-commits
mailing list