[cfe-commits] r97471 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-enum.cpp
Douglas Gregor
dgregor at apple.com
Mon Mar 1 11:00:07 PST 2010
Author: dgregor
Date: Mon Mar 1 13:00:07 2010
New Revision: 97471
URL: http://llvm.org/viewvc/llvm-project?rev=97471&view=rev
Log:
When instantiating a function-scoped enum, make sure that it and its
enumeration constants get placed into the local instantiation hash
table. Fixes PR6375.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaTemplate/instantiate-enum.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=97471&r1=97470&r2=97471&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Mar 1 13:00:07 2010
@@ -3433,7 +3433,7 @@
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;
}
};
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=97471&r1=97470&r2=97471&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Mar 1 13:00:07 2010
@@ -491,6 +491,9 @@
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 @@
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);
+ }
}
}
Modified: cfe/trunk/test/SemaTemplate/instantiate-enum.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-enum.cpp?rev=97471&r1=97470&r2=97471&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-enum.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-enum.cpp Mon Mar 1 13:00:07 2010
@@ -9,3 +9,19 @@
};
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>();
+}
More information about the cfe-commits
mailing list