]> granicus.if.org Git - clang/commitdiff
When defining a forward-declared enum, don't try to attach the definition to
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 23 Mar 2012 23:09:08 +0000 (23:09 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 23 Mar 2012 23:09:08 +0000 (23:09 +0000)
a previous declaration if the redeclaration is invalid. That way lies madness.
Fixes a crash-on-invalid reported by Abramo.

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

docs/ReleaseNotes.html
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
lib/Sema/SemaTemplateInstantiate.cpp
test/SemaCXX/enum-scoped.cpp
www/cxx_status.html

index 628079978e7329f15c69f67dd4d472d02d9d611b..64c6acb25aeb5b8374058c13388cb63ba12c0e9f 100644 (file)
@@ -125,6 +125,7 @@ following are now considered to be of production quality:
   <li>Generalized initializers</li>
   <li>Unrestricted unions</li>
   <li>User-defined literals</li>
+  <li>Forward-declared enumerations</li>
 </ul>
 
 <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
index 36232b1e98af4257c3b4f16e4d8e20f52dace22e..405ae906e504c4b9dfca6c12c9c91438342595f1 100644 (file)
@@ -1276,6 +1276,8 @@ def err_enum_class_reference : Error<
   "not 'enum class'">;
 def err_only_enums_have_underlying_types : Error<
   "only enumeration types have underlying types">;
+def err_unscoped_enum_defined_out_of_class : Error<
+  "out-of-line definition of unscoped enumeration member is not supported">;
 
 // C++11 delegating constructors
 def err_delegating_ctor : Error<
index 71f567f47ab5b72d7e0e3862598b3215a5d38e6f..68b27ef1f983633813a5edc9169e01349f8f1f07 100644 (file)
@@ -8260,10 +8260,11 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
             EnumUnderlyingTy = QualType(T, 0);
 
           // All conflicts with previous declarations are recovered by
-          // returning the previous declaration.
+          // returning the previous declaration, unless this is a definition,
+          // in which case we want the caller to bail out.
           if (CheckEnumRedeclaration(NameLoc.isValid() ? NameLoc : KWLoc,
                                      ScopedEnum, EnumUnderlyingTy, PrevEnum))
-            return PrevTagDecl;
+            return TUK == TUK_Declaration ? PrevTagDecl : 0;
         }
 
         if (!Invalid) {
index afa65ea9ee4daea09d32bea6a00661f9331438af..307cccce8bcf785a418685cf174b080c23292a04 100644 (file)
@@ -1848,7 +1848,8 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
         // specialization causes the implicit instantiation of the definitions
         // of unscoped member enumerations.
         // Record a point of instantiation for this implicit instantiation.
-        if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped()) {
+        if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
+            Enum->isCompleteDefinition()) {
           MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
           assert(MSInfo && "no spec info for member enum specialization");
           MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
index 31190bebaa354bfd9425e1a4a7ac255465685d9d..44394296e37d30776a30a9ada1003ac0c3c966b4 100644 (file)
@@ -189,3 +189,14 @@ namespace test7 {
   enum class E { e = (struct S*)0 == (struct S*)0 };
   S *p;
 }
+
+namespace test8 {
+  template<typename T> struct S {
+    enum A : int; // expected-note {{here}}
+    enum class B; // expected-note {{here}}
+    enum class C : int; // expected-note {{here}}
+  };
+  template<typename T> enum S<T>::A { a }; // expected-error {{previously declared with fixed underlying type}}
+  template<typename T> enum class S<T>::B : char { b }; // expected-error {{redeclared with different underlying}}
+  template<typename T> enum S<T>::C : int { c }; // expected-error {{previously declared as scoped}}
+}
index 28da5f096bf8745652b1e60170ac53a61087d115..8305b73ec65213a7315a85c357032e65cc37fef6 100644 (file)
@@ -158,7 +158,7 @@ with clang; other versions have not been tested.</p>
       <td>Forward declarations for enums</td>
       <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf">N2764</a>
       <br><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1206">DR1206</a></td>
-      <td class="none" align="center">No</td>
+      <td class="svn" align="center">SVN</td>
     </tr>
     <tr>
       <td>Generalized attributes</td>