[cfe-dev] Missing implicit cast when parsing C++ ?

Abramo Bagnara abramo.bagnara at gmail.com
Wed Apr 6 09:43:34 PDT 2011


Il 06/04/2011 16:31, Enea Zaffanella ha scritto:
> According to the C++ standard, the operand of the logical negation
> operator (!) is implicitly converted to type bool
> (C++98/03 5.3.1p8, C++0x 5.3.1p9).
> 
> However, parsing this C++ code fragment using clang
> 
> bool foo() { return !1234; }
> 
> we obtain the following AST, with no implicit cast:
> 
> bool foo() (CompoundStmt 0x479b2f8 <ex.cc:1:12, col:28>
>   (ReturnStmt 0x479b2d8 <col:14, col:22>
>     (UnaryOperator 0x479b2b8 <col:21, col:22> '_Bool' prefix '!'
>       (IntegerLiteral 0x479b290 <col:22> 'int' 1234))))
> 
> Usually, clang inserts all implicit casts in its AST.
> Is the behavior above a _meant_ exception to this general rule?
> 
> (Side note: if the integer literal is replaced by some non-boolean
> variable, an CK_LValueToRValue implicit cast is added, but again no cast
> from the variable type to the Boolean type.)

I've attached a candidate patch to fix this. Ok to commit?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LNot-casts.patch
Type: text/x-patch
Size: 929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110406/4ed93668/attachment.bin>


More information about the cfe-dev mailing list