Skip to content

Commit fd35333

Browse files
authored
Merge pull request #80585 from swiftlang/gaborh/not-imported-return-type-on-6.2
[6.2][cxx-interop] Fix not importing return type for certain functions
2 parents 60dced5 + 789359c commit fd35333

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

+9-1
Original file line numberDiff line numberDiff 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);

test/Interop/Cxx/foreign-reference/Inputs/inheritance.h

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
// A wrapper around C++'s static_cast(), which allows Swift to get around interop's current lack of support for inheritance.
66
template <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.
916
struct
1017
__attribute__((swift_attr("import_reference")))

test/Interop/Cxx/foreign-reference/inheritance.swift

+3-1
Original file line numberDiff line numberDiff 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

2931
InheritanceTestSuite.test("Templated cast to itself") {

0 commit comments

Comments
 (0)