[cfe-commits] r96283 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/instantiate-local-class.cpp
Chandler Carruth
chandlerc at gmail.com
Mon Feb 15 14:12:26 PST 2010
Author: chandlerc
Date: Mon Feb 15 16:12:26 2010
New Revision: 96283
URL: http://llvm.org/viewvc/llvm-project?rev=96283&view=rev
Log:
Fix instantiation of template functions with local classes that contain virtual
methods.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=96283&r1=96282&r2=96283&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Mon Feb 15 16:12:26 2010
@@ -1130,9 +1130,18 @@
// If this is a polymorphic C++ class without a key function, we'll
// have to mark all of the virtual members to allow emission of a vtable
// in this translation unit.
- if (Instantiation->isDynamicClass() && !Context.getKeyFunction(Instantiation))
+ if (Instantiation->isDynamicClass() &&
+ !Context.getKeyFunction(Instantiation)) {
+ // Local classes need to have their methods instantiated immediately in
+ // order to have the correct instantiation scope.
+ if (Instantiation->isLocalClass()) {
+ MarkVirtualMembersReferenced(PointOfInstantiation,
+ Instantiation);
+ } else {
ClassesWithUnmarkedVirtualMembers.push_back(std::make_pair(Instantiation,
PointOfInstantiation));
+ }
+ }
if (!Invalid)
Consumer.HandleTagDeclDefinition(Instantiation);
Modified: cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp?rev=96283&r1=96282&r2=96283&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp Mon Feb 15 16:12:26 2010
@@ -32,3 +32,21 @@
}
}
+// Instantiation of local classes with virtual functions.
+namespace local_class_with_virtual_functions {
+ template <typename T> struct X { };
+ template <typename T> struct Y { };
+
+ template <typename T>
+ void f() {
+ struct Z : public X<Y<T>*> {
+ virtual void g(Y<T>* y) { }
+ void g2(int x) {(void)x;}
+ };
+ Z z;
+ (void)z;
+ }
+
+ struct S { };
+ void test() { f<S>(); }
+}
More information about the cfe-commits
mailing list