@@ -1922,6 +1922,30 @@ void importer::addEntryToLookupTable(SwiftLookupTable &table,
19221922 }
19231923 }
19241924
1925+ // Class template instantiations are imported lazily, however, the lookup
1926+ // table must include their mangled name (__CxxTemplateInst...) to make it
1927+ // possible to find these decls during deserialization. For any C++ typedef
1928+ // that defines a name for a class template instantiation (e.g. std::string),
1929+ // import the mangled name of this instantiation, and add it to the table.
1930+ if (auto typedefNameDecl = dyn_cast<clang::TypedefNameDecl>(named)) {
1931+ auto underlyingDecl = typedefNameDecl->getUnderlyingType ()->getAsTagDecl ();
1932+
1933+ if (auto specializationDecl =
1934+ dyn_cast_or_null<clang::ClassTemplateSpecializationDecl>(
1935+ underlyingDecl)) {
1936+ auto name = nameImporter.importName (specializationDecl, currentVersion);
1937+
1938+ // Avoid adding duplicate entries into the table.
1939+ auto existingEntries =
1940+ table.lookup (DeclBaseName (name.getDeclName ().getBaseName ()),
1941+ name.getEffectiveContext ());
1942+ if (existingEntries.empty ()) {
1943+ table.addEntry (name.getDeclName (), specializationDecl,
1944+ name.getEffectiveContext ());
1945+ }
1946+ }
1947+ }
1948+
19251949 // Walk the members of any context that can have nested members.
19261950 if (isa<clang::TagDecl>(named) || isa<clang::ObjCInterfaceDecl>(named) ||
19271951 isa<clang::ObjCProtocolDecl>(named) ||
0 commit comments