[cfe-dev] static_cast and dynamic_cast semantic checks
Doug Gregor
doug.gregor at gmail.com
Thu Oct 30 07:42:39 PDT 2008
On Thu, Oct 30, 2008 at 11:19 AM, Sebastian Redl
<sebastian.redl at getdesigned.at> wrote:
> Doug Gregor wrote:
>> + // C++ 5.2.7p5
>> + // Upcasts are resolved statically.
>> + if (DestRecord && IsDerivedFrom(SrcPointee, DestPointee)) {
>> + CheckDerivedToBaseConversion(SrcPointee, DestPointee, OpLoc,
>> SourceRange());
>> + // Diagnostic already emitted on error.
>> + return;
>> + }
>>
>> Shouldn't the last argument to CheckDerivedToBaseConversion be the
>> source range containing the full static_cast expression?
>>
>
> Could be. On the other hand, I never mark the entire cast expression on
> conversion errors that involve both source and destination, so it would be a
> bit inconsistent.
Hmmm... actually, I think I'd prefer if errors that involve both
source and destination always marked the whole cast expression. It
doesn't matter much in a terminal, but in an IDE it would be really
nice for the whole erroneous express to be marked.
>>
>> bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType
>> ToType)
>> {
>> const BuiltinType *To = ToType->getAsBuiltinType();
>> + if (!To) {
>> + return false;
>> + }
>>
>> // An rvalue of type char, signed char, unsigned char, short int, or
>> // unsigned short int can be converted to an rvalue of type int if
>> // int can represent all the values of the source type; otherwise,
>> // the source rvalue can be converted to an rvalue of type unsigned
>> // int (C++ 4.5p1).
>> - if (FromType->isPromotableIntegerType() &&
>> !FromType->isBooleanType() && To) {
>> + if (FromType->isPromotableIntegerType() && !FromType->isBooleanType())
>> {
>>
>> You only need the top change or the bottom change, not both; I suggest
>> keeping the top one.
>>
>
> You seem to have this backward. There's a check for To not being null in
> your existing code. Since my newly introduced check assures this, I removed
> yours.
Yep, you're right. Thanks!
- Doug
More information about the cfe-dev
mailing list