Microsoft allows code like this:

struct S {
   enum E { a };
};

int i = S::E::a;   // C4482
http://msdn.microsoft.com/en-us/library/ms173704.aspx
int j = S::a;   // OK

This is my attempt to make this compile this when -fms-extensions is
used. I think that my comment could be better but I'm not very good at
explaining these things. I have no idea what to do with this test file
so I'm attaching it in addition to the patch. What do you think?
Index: lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- lib/Sema/SemaCXXScopeSpec.cpp       (revision 155007)
+++ lib/Sema/SemaCXXScopeSpec.cpp       (working copy)
@@ -283,16 +283,20 @@
 
   // Determine whether we have a class (or, in C++11, an enum) or
   // a typedef thereof. If so, build the nested-name-specifier.
+  // In Microsoft mode scoped enumerators are allowed in C++98.
   QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
   if (T->isDependentType())
     return true;
   else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
     if (TD->getUnderlyingType()->isRecordType() ||
         (Context.getLangOpts().CPlusPlus0x &&
+         TD->getUnderlyingType()->isEnumeralType()) ||
+        (Context.getLangOpts().MicrosoftExt &&
          TD->getUnderlyingType()->isEnumeralType()))
       return true;
   } else if (isa<RecordDecl>(SD) ||
-             (Context.getLangOpts().CPlusPlus0x && isa<EnumDecl>(SD)))
+             (Context.getLangOpts().CPlusPlus0x && isa<EnumDecl>(SD)) ||
+             (Context.getLangOpts().MicrosoftExt && isa<EnumDecl>(SD)))
     return true;
 
   return false;
// RUN: %clang_cc1 -fsyntax-only -fms-extensions -verify %s

enum E {
  E_Enumerator
};

typedef enum TE {
  TE_Enumerator
} TE;

struct S {
  enum E {
    E_Enumerator
  };
};

template <typename T>
struct ST {
  enum E {
    E_Enumerator
  };
};

E e = E::E_Enumerator;

TE te = TE::TE_Enumerator;

S::E s = S::E::E_Enumerator;

ST<int>::E st = ST<int>::E::E_Enumerator;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to