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

Eli Friedman eli.friedman at gmail.com
Wed Apr 6 11:44:08 PDT 2011


On Wed, Apr 6, 2011 at 7:31 AM, Enea Zaffanella <zaffanella at cs.unipr.it> wrote:
> 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?

Probably nobody noticed... the C definition of "!x" is "x==0", and in
practice that's the same as the definition in C++.

-Eli




More information about the cfe-dev mailing list