File tree 3 files changed +19
-2
lines changed
test/Interop/Cxx/foreign-reference
3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -3730,6 +3730,13 @@ namespace {
3730
3730
return nullptr;
3731
3731
}
3732
3732
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
+
3733
3740
Decl *importFunctionDecl(
3734
3741
const clang::FunctionDecl *decl, ImportedName importedName,
3735
3742
std::optional<ImportedName> correctSwiftName,
@@ -3865,7 +3872,8 @@ namespace {
3865
3872
3866
3873
bool importFuncWithoutSignature =
3867
3874
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)) {
3869
3877
// Handle initializers.
3870
3878
if (name.getBaseName().isConstructor()) {
3871
3879
assert(!accessorInfo);
Original file line number Diff line number Diff line change 5
5
// A wrapper around C++'s static_cast(), which allows Swift to get around interop's current lack of support for inheritance.
6
6
template <class I , class O > O cxxCast (I i) { return static_cast <O>(i); }
7
7
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
+
8
15
// A minimal foreign reference type.
9
16
struct
10
17
__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") {
23
23
let sc : BaseT = cast ( s)
24
24
expectFalse ( sc. isBase)
25
25
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)
27
29
}
28
30
29
31
InheritanceTestSuite . test ( " Templated cast to itself " ) {
You can’t perform that action at this time.
0 commit comments