// 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);
}
}
+// 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>(); }
+}