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

Abramo Bagnara abramo.bagnara at gmail.com
Thu Apr 7 02:31:06 PDT 2011


Il 07/04/2011 08:57, John McCall ha scritto:
> 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.

Committed in r129066.

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

This would be incongruent with C99 6.5.3.3p5.

Think also for:

int f(void* p) {
  return !p;
}

if we put an implicit cast around p we'd be forced to change logical not
argument type and to violate the standard.



More information about the cfe-dev mailing list