On Sep 26, 2010, at 8:38 PM, Francois Pichet wrote:

> Hi,
> 
> This patch makes an enum type complete at tag declaration in Microsoft mode.
> The underlying type is always int.
> 
> It allows code like this:
> enum TEST {
>    a = (TEST) 1
> };
> 
> enum TEST2;
> TEST2 var;
> 
> This patch get rid of about 100 errors when parsing msvc header files.

Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp       (revision 114808)
+++ lib/Sema/SemaDecl.cpp       (working copy)
@@ -5753,6 +5753,14 @@
     // enum X { A, B, C } D;    D should chain to X.
     New = EnumDecl::Create(Context, SearchDC, Loc, Name, KWLoc,
                            cast_or_null<EnumDecl>(PrevDecl));
+
+    // 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.

@@ -7174,8 +7182,13 @@
       ECD->setType(NewTy);
   }
 
-  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.

        - Doug
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to