Skip to content

Commit a353d6f

Browse files
committed
[cxx-interop] Fix lazy member lookup for forward-declared structs inside of a namespace.
1 parent f38f3ff commit a353d6f

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,8 +1967,14 @@ void importer::addEntryToLookupTable(SwiftLookupTable &table,
19671967
if (!alreadyAdded.insert(canonicalMember).second)
19681968
continue;
19691969

1970-
if (auto namedMember = dyn_cast<clang::NamedDecl>(canonicalMember))
1970+
if (auto namedMember = dyn_cast<clang::NamedDecl>(canonicalMember)) {
1971+
// Make sure we're looking at the definition, otherwise, there won't
1972+
// be any members to add.
1973+
if (auto recordDecl = dyn_cast<clang::RecordDecl>(namedMember))
1974+
if (auto def = recordDecl->getDefinition())
1975+
namedMember = def;
19711976
addEntryToLookupTable(table, namedMember, nameImporter);
1977+
}
19721978
}
19731979
}
19741980
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef TEST_INTEROP_CXX_CLASS_INPUTS_FORWARD_DECLARED_IN_NAMESPACE_H
2+
#define TEST_INTEROP_CXX_CLASS_INPUTS_FORWARD_DECLARED_IN_NAMESPACE_H
3+
4+
namespace Space {
5+
6+
struct C;
7+
8+
struct C {
9+
void test() const;
10+
};
11+
12+
}
13+
14+
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_FORWARD_DECLARED_IN_NAMESPACE_H

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,9 @@ module ForwardDeclaredCxxRecord {
105105

106106
module ReturnsLargeClass {
107107
header "returns-large-class.h"
108+
}
109+
110+
module ForwardDeclaredInNamespace {
111+
header "forward-declared-in-namespace.h"
108112
requires cplusplus
109113
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-experimental-cxx-interop
2+
3+
import ForwardDeclaredInNamespace
4+
5+
public func test(c: Space.C) { c.test() }

0 commit comments

Comments
 (0)