]> granicus.if.org Git - clang/commitdiff
Complain when an unnamed enumeration has no enumerations (in
authorDouglas Gregor <dgregor@apple.com>
Tue, 13 Jul 2010 06:24:26 +0000 (06:24 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 13 Jul 2010 06:24:26 +0000 (06:24 +0000)
C++). Fixes PR7466.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108231 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Parser/cxx-class.cpp
test/SemaCXX/enum.cpp

index 318ae494f137cb75a50e218725f4d694ca408256..7d90792376d59c2685fe3a5d6f880e9723ad3820 100644 (file)
@@ -1539,6 +1539,14 @@ Sema::DeclPtrTy Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
       return DeclPtrTy::make(Tag);
   }
   
+  if (getLangOptions().CPlusPlus && 
+      DS.getStorageClassSpec() != DeclSpec::SCS_typedef)
+    if (EnumDecl *Enum = dyn_cast_or_null<EnumDecl>(Tag))
+      if (Enum->enumerator_begin() == Enum->enumerator_end() &&
+          !Enum->getIdentifier() && !Enum->isInvalidDecl())
+        Diag(Enum->getLocation(), diag::ext_no_declarators)
+          << DS.getSourceRange();
+      
   if (!DS.isMissingDeclaratorOk() &&
       DS.getTypeSpecType() != DeclSpec::TST_error) {
     // Warn about typedefs of enums without names, since this is an
index 4abbbc5b9b580a33f1fcd885f7c613cfe13504a5..57831a463b9bb9b947517d19f1e85a6544c7b586 100644 (file)
@@ -7,7 +7,7 @@ protected:
   static int sf(), u;
 
   struct S {};
-  enum {};
+  enum {}; // expected-warning{{declaration does not declare anything}}
   int; // expected-warning {{declaration does not declare anything}}
   int : 1, : 2;
 
index 3a66617e0d191bc4f487cd5848f4d12c37994de2..0690ead250859d9810266803fac965a3362e66c7 100644 (file)
@@ -81,3 +81,7 @@ namespace PR7051 {
     e |= 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}}
   }
 }
+
+// PR7466
+enum { }; // expected-warning{{declaration does not declare anything}}
+typedef enum { }; // expected-warning{{typedef requires a name}}