Improper implicit pointer cast in AST

Sebastian Redl sebastian.redl at getdesigned.at
Thu Sep 4 07:15:05 PDT 2014


On 04 Sep 2014, at 15:23, Abramo Bagnara <abramo.bagnara at bugseng.com> wrote:

> Il 04/09/2014 15:13, Abramo Bagnara ha scritto:
>> 
>> For the following source
>> 
>> void f() {
>>  char *p;
>>  const char *cp;
>>  p == cp;
>>  p != cp;
>>  p < cp;
>>  p <= cp;
>>  p > cp;
>>  p >= cp;
>>  p - cp;
>> }
>> 
>> clang (unexpectedly for me) emits an implicit cast from const char * to
>> char * (i.e. it remove a qualifier) for all the relational and equality
> 
> BTW: this violates C++11 5.9p2 where it is said that
> 
> "Otherwise, the composite pointer type is a pointer type similar (4.4)
> to the type of one of the operands, with a cv-qualification signature
> (4.4) that is the union of the cv-qualification signatures of the
> operand types.”
> 

Interestingly enough, if I compile it as C, I get the const -> non-const casts, whereas as C++, I get them the other way round, conforming to the standard.

C++:
    |-BinaryOperator 0x102824568 <line:4:2, col:7> '_Bool' '=='
    | |-ImplicitCastExpr 0x102824550 <col:2> 'const char *' <NoOp>
    | | `-ImplicitCastExpr 0x102824520 <col:2> 'char *' <LValueToRValue>
    | |   `-DeclRefExpr 0x1028244d0 <col:2> 'char *' lvalue Var 0x1028243b0 'p' 'char *'
    | `-ImplicitCastExpr 0x102824538 <col:7> 'const char *' <LValueToRValue>
    |   `-DeclRefExpr 0x1028244f8 <col:7> 'const char *' lvalue Var 0x102824460 'cp' 'const char *'

C:
    |-BinaryOperator 0x1028224b8 <line:4:2, col:7> 'int' '=='
    | |-ImplicitCastExpr 0x102822470 <col:2> 'char *' <LValueToRValue>
    | | `-DeclRefExpr 0x102822420 <col:2> 'char *' lvalue Var 0x102822300 'p' 'char *'
    | `-ImplicitCastExpr 0x1028224a0 <col:7> 'char *' <BitCast>
    |   `-ImplicitCastExpr 0x102822488 <col:7> 'const char *' <LValueToRValue>
    |     `-DeclRefExpr 0x102822448 <col:7> 'const char *' lvalue Var 0x1028223b0 'cp' 'const char *'
 
So it appears to be separate code paths for the two languages.

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


More information about the cfe-commits mailing list