Use the 'declaration does not declare anything' error when we see an anonymous struct/union declaration outside of a struct or union in C

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66303 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 50113ee..5e7ce52 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -922,8 +922,14 @@
 
   if (RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag)) {
     if (!Record->getDeclName() && Record->isDefinition() &&
-        DS.getStorageClassSpec() != DeclSpec::SCS_typedef)
-      return BuildAnonymousStructOrUnion(S, DS, Record);
+        DS.getStorageClassSpec() != DeclSpec::SCS_typedef) {
+      if (getLangOptions().CPlusPlus ||
+          Record->getDeclContext()->isRecord())
+        return BuildAnonymousStructOrUnion(S, DS, Record);
+
+      Diag(DS.getSourceRange().getBegin(), diag::err_no_declarators)
+        << DS.getSourceRange();
+    }
 
     // Microsoft allows unnamed struct/union fields. Don't complain
     // about them.
@@ -1102,14 +1108,7 @@
           Invalid = true;
       }
     }
-  } else {
-    // FIXME: Check GNU C semantics
-    if (Record->isUnion() && !Owner->isRecord()) {
-      Diag(Record->getLocation(), diag::err_anonymous_union_not_member)
-        << (int)getLangOptions().CPlusPlus;
-      Invalid = true;
-    }
-  }
+  } 
 
   if (!Record->isUnion() && !Owner->isRecord()) {
     Diag(Record->getLocation(), diag::err_anonymous_struct_not_member)