[cfe-dev] Why the argument of `delete' is converted to void* ?

Abramo Bagnara abramo.bagnara at gmail.com
Wed Jul 4 05:42:32 PDT 2012


Il 04/07/2012 14:01, Jean-Daniel Dupas ha scritto:
> 
> Le 4 juil. 2012 à 12:42, Enea Zaffanella a écrit :
> 
>> We have noticed that, in the AST produced by clang, the expression 
>> argument of a CXXDeleteExpr node is implicitly converted to void*:
>>
>> # cat delete.cc
>> struct S {};
>>
>> void free(S* ps) {
>>   delete ps;
>> }
>>
>> # llvm/Debug+Asserts/bin/clang -cc1 -ast-dump delete.cc
>> [...]
>> void free(S *ps) (CompoundStmt 0x4822650 <delete.cc:3:18, line:5:1>
>>   (CXXDeleteExpr 0x4822628 <line:4:3, col:10> 'void'
>>     (ImplicitCastExpr 0x4821df8 <col:10> 'void *' <BitCast>
>>       (ImplicitCastExpr 0x4821de0 <col:10> 'struct S *' <LValueToRValue>
>>         (DeclRefExpr 0x4821db8 <col:10> 'struct S *' lvalue ParmVar 
>> 0x47eeb20 'ps' 'struct S *')))))
>>
>>
>> What are the reasons for introducing such an implicit cast?
>>
>> Enea.
> 
> Just a though, but isn't it because the signature of delete is:
> 
> operator delete(void *);

I don't think so:

delete ptr;

is something very different from

operator delete(ptr);



More information about the cfe-dev mailing list