diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index fe1747bfb6a..b93884a9614 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -4940,6 +4940,10 @@ TinyPtrVector ClangRecordMemberLookup::evaluate( auto named = found.get(); if (dyn_cast(named->getDeclContext()) == recordDecl->getClangDecl()) { + // Don't import constructors on foreign reference types. + if (isa(named) && isa(recordDecl)) + continue; + if (auto import = clangModuleLoader->importDeclDirectly(named)) result.push_back(cast(import)); } diff --git a/test/Interop/Cxx/foreign-reference/no-ctor-errors.swift b/test/Interop/Cxx/foreign-reference/no-ctor-errors.swift new file mode 100644 index 00000000000..b8155509e8f --- /dev/null +++ b/test/Interop/Cxx/foreign-reference/no-ctor-errors.swift @@ -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) \ No newline at end of file