[cfe-commits] [PATCH][MS][Review request] - microsoft enum complete at tag

Francois Pichet pichet2000 at gmail.com
Tue Oct 5 06:59:04 PDT 2010


Hi here is an updated patch

On Fri, Oct 1, 2010 at 10:29 AM, Douglas Gregor <dgregor at apple.com> wrote:
> +
> +    // Make enum type a complete definition on Tag declaration in Microsoft
> +    //mode. Default to int type. Needed for enum forward declaration.
> +    if (getLangOptions().Microsoft) {
> +      EnumDecl *NewEnum = cast<EnumDecl>(New);
> +      NewEnum->completeDefinition(Context.IntTy, Context.IntTy, 0, 0);
> +    }
> +
>
> 0, 0 seems a bit strange... I suggest we use the number of negative/positive bits in an int.
>
I did
      NewEnum->completeDefinition(Context.IntTy, Context.IntTy,
                                  Context.Target.getIntWidth() - 1,
                                  Context.Target.getIntWidth());
which is equivalent to this enum:
enum E { e1 = INT_MAX, INT_MIN };


>
> -  Enum->completeDefinition(BestType, BestPromotionType,
> -                           NumPositiveBits, NumNegativeBits);
> +  // In Microsoft mode, enums are already complete type in ActOnTag.
> +  if (getLangOptions().Microsoft) {
> +    Enum->setNumPositiveBits(NumPositiveBits);
> +    Enum->setNumNegativeBits(NumNegativeBits);
> +  } else
> +    Enum->completeDefinition(BestType, BestPromotionType,
> +                             NumPositiveBits, NumNegativeBits);
>  }
>
> We're missing semantic validation here; we've completed the enum with an underlying type of "int", but we haven't converted all of the enumerator types to "int" and we haven't verified that all of the enumerator values fall into the range of an int, e.g.,
>
>        enum E { e1 = INT_MAX + 1 };
>
> seems like it should be an error in Microsoft mode, and we should truncate the value to the size of an int, but it depends on how the Microsoft compiler deals with large enumerators.

Ok, I skipped the part where sema selects the underlying type in
Microsoft mode. Microsoft enums are always int and will silently
convert any enumerator value to int. I believe this is what clang will
do also.

Then there is the enum E : unsigned short {e}; syntax supported since
VS 2005. But I'll keep that for later since I think someone is already
working on adding this to clang.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: enum_complete_type_tag.patch
Type: application/octet-stream
Size: 8651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20101005/8ee04266/attachment.obj>


More information about the cfe-commits mailing list