[cfe-dev] Nested implicit casts?

Douglas Gregor dgregor at apple.com
Mon Jan 11 10:12:35 PST 2010


On Jan 11, 2010, at 10:58 AM, Enea Zaffanella wrote:

> Hello.
>
> Dumping the AST for the following program:
>
> int f(signed char v) { return v < 1U; }
>
> we obtain an implicit cast expression that (immediately) contains
> another implicit cast expression:
>
> int f(signed char v) (CompoundStmt 0x174c530 <test.c:1:22, col:39>
>   (ReturnStmt 0x174c510 <col:24, col:35>
>     (BinaryOperator 0x174c4d0 <col:31, col:35> 'int' '<'
>       (ImplicitCastExpr 0x174c4a0 <col:31> 'unsigned int' <Unknown>
>         (ImplicitCastExpr 0x174c470 <col:31> 'int' <IntegralCast>
>           (DeclRefExpr 0x174c3f8 <col:31> 'signed char' ParmVar='v'
> 0x174c2c0)))
>       (IntegerLiteral 0x174c430 <col:35> 'unsigned int' 1))))
>
>
> Is that meant to be OK?
>
> I am asking because, when looking to dumps from older clang  
> revisions, I
> got the (probably false) impression that some effort was done in order
> to merge chains of consecutive implicit casts into a single one.

When those conversions are conceptually the same kind of conversion,  
we do want to merge the two implicit casts into a single implicit cast.

> Is it the case that now the two casts are not merged because they have
> different kind (one is an IntegralCast, the other is Unknown)?


Yes, although we'd really like to fix that outer cast so that it is  
not of type 'Unknown'. The unknown cast kind is meant to go away.

	- Doug



More information about the cfe-dev mailing list