Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp	(revision 112697)
+++ lib/Sema/SemaDecl.cpp	(working copy)
@@ -1898,10 +1898,14 @@
       } else if (RecordDecl *MemRecord = dyn_cast<RecordDecl>(*Mem)) {
         if (!MemRecord->isAnonymousStructOrUnion() &&
             MemRecord->getDeclName()) {
-          // This is a nested type declaration.
-          Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type)
-            << (int)Record->isUnion();
-          Invalid = true;
+          // Visual C++ allows type definition in anonymous struct or union.
+          if (!getLangOptions().Microsoft)
+          {
+            // This is a nested type declaration.
+            Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type)
+              << (int)Record->isUnion();
+            Invalid = true;
+          }
         }
       } else if (isa<AccessSpecDecl>(*Mem)) {
         // Any access specifier is fine.
@@ -1915,9 +1919,15 @@
           DK = diag::err_anonymous_record_with_function;
         else if (isa<VarDecl>(*Mem))
           DK = diag::err_anonymous_record_with_static;
-        Diag((*Mem)->getLocation(), DK)
-            << (int)Record->isUnion();
-          Invalid = true;
+        
+        // Visual C++ allows type definition in anonymous struct or union.
+        if (!getLangOptions().Microsoft ||
+            DK != diag::err_anonymous_record_with_type)
+        {
+          Diag((*Mem)->getLocation(), DK)
+              << (int)Record->isUnion();
+            Invalid = true;
+        }
       }
     }
   }
Index: test/SemaCXX/MicrosoftExtensions.cpp
===================================================================
--- test/SemaCXX/MicrosoftExtensions.cpp	(revision 112697)
+++ test/SemaCXX/MicrosoftExtensions.cpp	(working copy)
@@ -29,3 +29,45 @@
   virtual void f2() throw(...);
   virtual void f3();
 };
+
+
+// MSVC allows type definition in anonymous union and struct
+struct A
+{
+  union 
+  {
+    int a;
+    struct B
+    { 
+      int c;
+    } d;
+
+    union C
+    {
+      int e;
+      int ee;
+    } f;
+
+    typedef int D;
+    struct F;
+  };
+
+  struct
+  {
+    int a2;
+
+    struct B2
+    {
+      int c2;
+    } d2;
+    
+	union C2
+    {
+      int e2;
+      int ee2;
+    } f2;
+
+    typedef int D2;
+    struct F2;
+  };
+};
