diff --git a/interpreter/llvm/src/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp b/interpreter/llvm/src/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp index 3c76a05bcae93..8d48fe5789ee3 100644 --- a/interpreter/llvm/src/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/interpreter/llvm/src/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2235,13 +2235,19 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, // Exit the scope of this instantiation. SavedContext.pop(); - Consumer.HandleTagDeclDefinition(Instantiation); + if (!Instantiation->isInvalidDecl()) { + // Always emit the vtable for an explicit instantiation definition + // of a polymorphic class template specialization. Otherwise, eagerly + // instantiate only constexpr virtual functions in preparation for their use + // in constant evaluation. + if (TSK == TSK_ExplicitInstantiationDefinition) + MarkVTableUsed(PointOfInstantiation, Instantiation, true); + else if (MightHaveConstexprVirtualFunctions) + MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation, + /*ConstexprOnly*/ true); + } - // Always emit the vtable for an explicit instantiation definition - // of a polymorphic class template specialization. - if (!Instantiation->isInvalidDecl() && - TSK == TSK_ExplicitInstantiationDefinition) - MarkVTableUsed(PointOfInstantiation, Instantiation, true); + Consumer.HandleTagDeclDefinition(Instantiation); return Instantiation->isInvalidDecl(); }