Integer promotions in C-style cast expressions?

Hello.

We have a question related to ImplicitCastExpr nodes.
Consider the following program:

void* foo(char c) {
   return (void*) c;
}

When fed to clang, we obtain the following AST:

void *foo(char c) (CompoundStmt 0x2a0bb90 <bug.c:1:19, line:3:1>
   (ReturnStmt 0x2a0de10 <line:2:3, col:18>
     (CStyleCastExpr 0x2a0c8c0 <col:10, col:18> 'void *'
       (ImplicitCastExpr 0x2a094b0 <col:18> 'int'
         (DeclRefExpr 0x2a09470 <col:18> 'char' ParmVar='c' 0x2a0dd70)))))

Namely, the use of the char 'c' is first implicitly converted to 'int' and then immediately cast to 'void*'. We guess that the ImplicitCastExpr node was added to model the integer promotion of the c-style cast operator.

However, according to our understanding of the C99 standard, the operator of a C-style cast expression is not subject to promotions.

Footnote 48 to C99 6.3.1.1p2 (page 43) says:

However, according to our understanding of the C99 standard, the
operator of a C-style cast expression is not subject to promotions.

Mmm... probably just that whoever wrote the code didn't consider the
difference between DefaultFunctionArrayConversion and
UsualUnaryConversions in this context, since it's not particularly
important in terms of generating the correct code.

Function UsualUnaryConversions mixes array/function decays and integral
promotions. In our opinion, operands of explicit casts should be subject
to type decay, but not to promotions.

That sounds fine; could you send a patch to cfe-commits?

-Eli

Eli Friedman wrote:

cast_no_promotion.diff (1.07 KB)

Applied in r79126.

-Eli