[cfe-dev] Surprising cast
Abramo Bagnara
abramo.bagnara at gmail.com
Fri Dec 17 04:28:35 PST 2010
Il 11/12/2010 23:33, John McCall ha scritto:
> On Dec 11, 2010, at 9:21 AM, Abramo Bagnara wrote:
>> $ cat p.c
>> enum {
>> a = 1
>> };
>> $ clang -cc1 -ast-dump p.c
>> typedef char *__builtin_va_list;
>> enum {
>> a = (ImplicitCastExpr 0xb9e11f0 <p.c:2:7> 'int' <IntegralCast>
>> (IntegerLiteral 0xb9e11a0 <col:7> 'int' 1))
>>
>> };
>>
>> The implicit cast from int to int is deliberate?
>
> Seems unnecessary to me; probably something is just making an explicit expression instead of using ImpCastExprToType (which would be appropriate here, I think).
Fixed in r122056.
A similar problem is this one:
$ cat p.cc
void foo() {
short s = (short) 1.3;
short t = (short) 2;
}
$ clang++ -cc1 -ast-dump p.cc
typedef char *__builtin_va_list;
void foo() (CompoundStmt 0xc00ae08 <p.cc:2:12, line:5:1>
(DeclStmt 0xc00ad30 <line:3:3, col:24>
0xc00aca0 "short s =
(CStyleCastExpr 0xc00ad10 <col:13, col:21> 'short' <NoOp>
(ImplicitCastExpr 0xc00ad00 <col:21> 'short' <FloatingToIntegral>
(FloatingLiteral 0xc00ace0 <col:21> 'double' 1.300000e+00)))")
(DeclStmt 0xc00adf0 <line:4:3, col:22>
0xc00ad60 "short t =
(CStyleCastExpr 0xc00add0 <col:13, col:21> 'short' <NoOp>
(ImplicitCastExpr 0xc00adc0 <col:21> 'short' <IntegralCast>
(IntegerLiteral 0xc00ada0 <col:21> 'int' 2)))"))
For unknown reasons the CStyleCastExpr is always converted to a NoOp and
an unneeded ImplicitCastExpr is added...
This happens only for C++... it is very weird IMHO.
What do you think about that?
More information about the cfe-dev
mailing list