]> granicus.if.org Git - clang/commitdiff
When instantiating a function-scoped enum, make sure that it and its
authorDouglas Gregor <dgregor@apple.com>
Mon, 1 Mar 2010 19:00:07 +0000 (19:00 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 1 Mar 2010 19:00:07 +0000 (19:00 +0000)
enumeration constants get placed into the local instantiation hash
table. Fixes PR6375.

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

lib/Sema/Sema.h
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-enum.cpp

index da192dd887957565a9c7e64a13000cdc2743cea7..4d017cada33bf9b9a0591ebf0d63a69adc3c4de7 100644 (file)
@@ -3433,7 +3433,7 @@ public:
     
     void InstantiatedLocal(const Decl *D, Decl *Inst) {
       Decl *&Stored = LocalDecls[D];
-      assert(!Stored && "Already instantiated this local");
+      assert((!Stored || Stored == Inst) && "Already instantiated this local");
       Stored = Inst;
     }
   };
index 0f7bae835fde469d371e8be23b272f123eba904d..292820b821c44911e0f484e66088f1a7085225ad 100644 (file)
@@ -491,6 +491,9 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
   Owner->addDecl(Enum);
   Enum->startDefinition();
 
+  if (D->getDeclContext()->isFunctionOrMethod())
+    SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Enum);
+    
   llvm::SmallVector<Sema::DeclPtrTy, 4> Enumerators;
 
   EnumConstantDecl *LastEnumConst = 0;
@@ -530,6 +533,12 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
       Enum->addDecl(EnumConst);
       Enumerators.push_back(Sema::DeclPtrTy::make(EnumConst));
       LastEnumConst = EnumConst;
+      
+      if (D->getDeclContext()->isFunctionOrMethod()) {
+        // If the enumeration is within a function or method, record the enum
+        // constant as a local.
+        SemaRef.CurrentInstantiationScope->InstantiatedLocal(*EC, EnumConst);
+      }
     }
   }
 
index 6f9aa4b116d75dc205eeac03d5aa57bc4fb2fe57..5353a92a90bc85c503c762c9acbf79082e4c1471 100644 (file)
@@ -9,3 +9,19 @@ struct adder {
 };
 
 int array1[adder<long, 3, 4>::value == 7? 1 : -1];
+
+namespace PR6375 {
+  template<typename T> 
+  void f() {
+    enum Enum
+    {
+      enumerator1 = 0xFFFFFFF,
+      enumerator2 = enumerator1 - 1
+    };
+  
+    int xb1 = enumerator1;
+    int xe1 = enumerator2;
+  }
+
+  template void f<int>();
+}