mirror of
https://github.com/apple/swift.git
synced 2026-03-04 18:24:35 +01:00
[cxx-interop] Don't import constructors of foreign reference types.
The logic is here for this in the importer, which means the module interface tests make it appear that the behavior is correct, but lazy member lookup still finds the constructors, so this patch fixes that part.
This commit is contained in:
@@ -4940,6 +4940,10 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
|
||||
auto named = found.get<clang::NamedDecl *>();
|
||||
if (dyn_cast<clang::Decl>(named->getDeclContext()) ==
|
||||
recordDecl->getClangDecl()) {
|
||||
// Don't import constructors on foreign reference types.
|
||||
if (isa<clang::CXXConstructorDecl>(named) && isa<ClassDecl>(recordDecl))
|
||||
continue;
|
||||
|
||||
if (auto import = clangModuleLoader->importDeclDirectly(named))
|
||||
result.push_back(cast<ValueDecl>(import));
|
||||
}
|
||||
|
||||
25
test/Interop/Cxx/foreign-reference/no-ctor-errors.swift
Normal file
25
test/Interop/Cxx/foreign-reference/no-ctor-errors.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
// RUN: rm -rf %t
|
||||
// RUN: split-file %s %t
|
||||
// RUN: not %target-swift-frontend -typecheck -I %t/Inputs %t/test.swift -enable-experimental-cxx-interop 2>&1 | %FileCheck %s
|
||||
|
||||
//--- Inputs/module.modulemap
|
||||
module Test {
|
||||
header "test.h"
|
||||
requires cplusplus
|
||||
}
|
||||
|
||||
//--- Inputs/test.h
|
||||
struct
|
||||
__attribute__((swift_attr("import_reference")))
|
||||
__attribute__((swift_attr("retain:immortal")))
|
||||
__attribute__((swift_attr("release:immortal")))
|
||||
HasCtor {
|
||||
HasCtor(int a) {}
|
||||
};
|
||||
|
||||
//--- test.swift
|
||||
|
||||
import Test
|
||||
|
||||
// CHECK: error: 'HasCtor' cannot be constructed because it has no accessible initializers
|
||||
let x = HasCtor(42)
|
||||
Reference in New Issue
Block a user