File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
test/Interop/Cxx/foreign-reference Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -3730,6 +3730,13 @@ namespace {
37303730 return nullptr ;
37313731 }
37323732
3733+ static bool isClangNamespace (const DeclContext *dc) {
3734+ if (const auto *ed = dc->getSelfEnumDecl ())
3735+ return isa<clang::NamespaceDecl>(ed->getClangDecl ());
3736+
3737+ return false ;
3738+ }
3739+
37333740 Decl *importFunctionDecl (
37343741 const clang::FunctionDecl *decl, ImportedName importedName,
37353742 std::optional<ImportedName> correctSwiftName,
@@ -3865,7 +3872,8 @@ namespace {
38653872
38663873 bool importFuncWithoutSignature =
38673874 isa<clang::CXXMethodDecl>(decl) && Impl.importSymbolicCXXDecls ;
3868- if (!dc->isModuleScopeContext () && !isa<clang::CXXMethodDecl>(decl)) {
3875+ if (!dc->isModuleScopeContext () && !isClangNamespace (dc) &&
3876+ !isa<clang::CXXMethodDecl>(decl)) {
38693877 // Handle initializers.
38703878 if (name.getBaseName ().isConstructor ()) {
38713879 assert (!accessorInfo);
Original file line number Diff line number Diff line change 55// A wrapper around C++'s static_cast(), which allows Swift to get around interop's current lack of support for inheritance.
66template <class I , class O > O cxxCast (I i) { return static_cast <O>(i); }
77
8+ namespace Foo {
9+ template <class I , class O >
10+ O cxxCast (I i) {
11+ return static_cast <O>(i);
12+ }
13+ } // namespace Foo
14+
815// A minimal foreign reference type.
916struct
1017__attribute__ ((swift_attr(" import_reference" )))
Original file line number Diff line number Diff line change @@ -23,7 +23,9 @@ InheritanceTestSuite.test("Templated cast to base") {
2323 let sc : BaseT = cast ( s)
2424 expectFalse ( sc. isBase)
2525 let sx : BaseT = cxxCast ( s) // should instantiate I to SubT and O to BaseT
26- expectFalse ( sc. isBase)
26+ expectFalse ( sx. isBase)
27+ let sy : BaseT = Foo . cxxCast ( s) // should instantiate I to SubT and O to BaseT
28+ expectFalse ( sy. isBase)
2729}
2830
2931InheritanceTestSuite . test ( " Templated cast to itself " ) {
You can’t perform that action at this time.
0 commit comments