[cfe-commits] [Request for review] Removing redundant implicit casts in the AST

Nicola Gigante nicola.gigante at gmail.com
Tue Oct 25 03:36:12 PDT 2011


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.

But I'm certainly not a language lawyer…

Anyway, if we want to make those cases explicit,
it looks like a bit more complex than other cases, because
simply changing those cases to use CastExprToType
doesn't seem to work out-of-the-box, and I need to
figure out what is happening.


Nicola


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111025/bcf54c50/attachment.html>


More information about the cfe-commits mailing list