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

John McCall rjmccall at apple.com
Wed Apr 6 23:57:48 PDT 2011


On Apr 6, 2011, at 7:31 AM, Enea Zaffanella 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:

We consistently insert these implicit conversions everywhere else
in C++ that converts to bool;  this isn't an intentional oversight.

Instead of going through an expensive re-analysis, since you
already know that we're converting a scalar to a bool (which
always suceeds), you can just switch on getScalarTypeKind() to
find the appropriate cast kind.  Feel free to extract the logic from
SemaExprCXX.cpp:2187 out into its own function for this purpose.

Also, I'm not really sure that there's a good reason for us to not
represent these explicitly in C, except for the design questions
around operands that are already of type 'int'.

John.



More information about the cfe-dev mailing list