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

Enea Zaffanella zaffanella at cs.unipr.it
Wed Apr 6 07:31:34 PDT 2011


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.)

Enea.



More information about the cfe-dev mailing list