Skip to content

Commit 445cbd7

Browse files
authored
Merge pull request #60778 from zoecarver/dont-import-reference-type-ctors
[cxx-interop] Don't import constructors of foreign reference types.
2 parents c8a3383 + 8df9fca commit 445cbd7

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4943,6 +4943,10 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
49434943
auto named = found.get<clang::NamedDecl *>();
49444944
if (dyn_cast<clang::Decl>(named->getDeclContext()) ==
49454945
recordDecl->getClangDecl()) {
4946+
// Don't import constructors on foreign reference types.
4947+
if (isa<clang::CXXConstructorDecl>(named) && isa<ClassDecl>(recordDecl))
4948+
continue;
4949+
49464950
if (auto import = clangModuleLoader->importDeclDirectly(named))
49474951
result.push_back(cast<ValueDecl>(import));
49484952
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: not %target-swift-frontend -typecheck -I %t/Inputs %t/test.swift -enable-experimental-cxx-interop 2>&1 | %FileCheck %s
4+
5+
//--- Inputs/module.modulemap
6+
module Test {
7+
header "test.h"
8+
requires cplusplus
9+
}
10+
11+
//--- Inputs/test.h
12+
struct
13+
__attribute__((swift_attr("import_reference")))
14+
__attribute__((swift_attr("retain:immortal")))
15+
__attribute__((swift_attr("release:immortal")))
16+
HasCtor {
17+
HasCtor(int a) {}
18+
};
19+
20+
//--- test.swift
21+
22+
import Test
23+
24+
// CHECK: error: 'HasCtor' cannot be constructed because it has no accessible initializers
25+
let x = HasCtor(42)

0 commit comments

Comments
 (0)