diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index a1560847e5ebb..81142f6abe052 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -3371,6 +3371,11 @@ namespace { } } + // If we've already imported this decl, skip it so we don't add the same + // member twice. + if (Impl.ImportedDecls.count({nd->getCanonicalDecl(), getVersion()})) + continue; + auto member = Impl.importDecl(nd, getActiveSwiftVersion()); if (!member) { if (!isa(nd) && !isa(nd)) { @@ -3383,11 +3388,6 @@ namespace { } if (auto nestedType = dyn_cast(member)) { - // Only import definitions. Otherwise, we might add the same member - // twice. - if (auto tagDecl = dyn_cast(nd)) - if (tagDecl->getDefinition() != tagDecl) - continue; nestedTypes.push_back(nestedType); continue; } diff --git a/test/Interop/Cxx/class/Inputs/nested-records.h b/test/Interop/Cxx/class/Inputs/nested-records.h index 90ccb5741a57d..a31b9449e7c52 100644 --- a/test/Interop/Cxx/class/Inputs/nested-records.h +++ b/test/Interop/Cxx/class/Inputs/nested-records.h @@ -51,6 +51,18 @@ struct HasForwardDeclaredNestedType { struct ForwardDeclaredType { }; }; +struct HasForwardDeclaredTemplateChild { + template struct ForwardDeclaredClassTemplate; + + struct DeclaresForwardDeclaredClassTemplateFriend { + template + friend struct HasForwardDeclaredTemplateChild::ForwardDeclaredClassTemplate; + }; + + template struct ForwardDeclaredClassTemplate { }; +}; + + // TODO: Nested class templates (SR-13853). #endif // TEST_INTEROP_CXX_CLASS_INPUTS_NESTED_RECORDS_H diff --git a/test/Interop/Cxx/class/nested-records-module-interface.swift b/test/Interop/Cxx/class/nested-records-module-interface.swift index f642a58fbbe7b..17017cd8616cb 100644 --- a/test/Interop/Cxx/class/nested-records-module-interface.swift +++ b/test/Interop/Cxx/class/nested-records-module-interface.swift @@ -57,10 +57,19 @@ // CHECK: } // CHECK: struct HasForwardDeclaredNestedType { +// CHECK: struct ForwardDeclaredType { +// CHECK: init() +// CHECK: } // CHECK: struct NormalSubType { // CHECK: init() // CHECK: } -// CHECK: struct ForwardDeclaredType { +// CHECK: init() +// CHECK: } + +// CHECK: struct HasForwardDeclaredTemplateChild { +// CHECK: struct ForwardDeclaredClassTemplate { +// CHECK: } +// CHECK: struct DeclaresForwardDeclaredClassTemplateFriend { // CHECK: init() // CHECK: } // CHECK: init()