Skip to content

Commit 40723a1

Browse files
authored
Merge pull request swiftlang#34538 from zoecarver/cxx/fix/same-nominal-in-namespace
[cxx-interop] Support class template specializations in namespaces.
2 parents b935c4a + c4363b9 commit 40723a1

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,6 +3326,14 @@ namespace {
33263326
continue;
33273327
}
33283328

3329+
if (auto recordDecl = dyn_cast<clang::RecordDecl>(m)) {
3330+
// An injected class name decl will just point back to the parent
3331+
// decl, so don't import it.
3332+
if (recordDecl->isInjectedClassName()) {
3333+
continue;
3334+
}
3335+
}
3336+
33293337
auto nd = dyn_cast<clang::NamedDecl>(m);
33303338
if (!nd) {
33313339
// We couldn't import the member, so we can't reference it in Swift.
@@ -3569,6 +3577,19 @@ namespace {
35693577
return VisitCXXRecordDecl(def);
35703578
}
35713579

3580+
Decl *VisitClassTemplateDecl(const clang::ClassTemplateDecl *decl) {
3581+
// When loading a namespace's sub-decls, we won't add template
3582+
// specilizations, so make sure to do that here.
3583+
for (auto spec : decl->specializations()) {
3584+
if (auto importedSpec = Impl.importDecl(spec, getVersion())) {
3585+
if (auto namespaceDecl =
3586+
dyn_cast<EnumDecl>(importedSpec->getDeclContext()))
3587+
namespaceDecl->addMember(importedSpec);
3588+
}
3589+
}
3590+
return nullptr;
3591+
}
3592+
35723593
Decl *VisitClassTemplatePartialSpecializationDecl(
35733594
const clang::ClassTemplatePartialSpecializationDecl *decl) {
35743595
// Note: partial template specializations are not imported.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Space {
2+
3+
template <class...> struct Ship;
4+
template <class T, class... Args> struct Ship<T(Args...)> {};
5+
6+
using Orbiter = Ship<void(bool)>;
7+
8+
} // namespace Space

test/Interop/Cxx/templates/Inputs/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ module ClassTemplateTemplateParameter {
5757
module ClassTemplateWithTypedef {
5858
header "class-template-with-typedef.h"
5959
}
60+
61+
module ClassTemplateInNamespace {
62+
header "class-template-in-namespace.h"
63+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=ClassTemplateInNamespace -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s
2+
3+
// CHECK: enum Space {
4+
// CHECK: struct __CxxTemplateInstN5Space4ShipIJFvbEEEE {
5+
// CHECK: init()
6+
// CHECK: }
7+
// CHECK: typealias Orbiter = Space.__CxxTemplateInstN5Space4ShipIJFvbEEEE
8+
// CHECK: }

0 commit comments

Comments
 (0)