Skip to content

Commit 79c68f8

Browse files
committed
[cxx-interop] Don't add incomplete records to lookup table.
1 parent ba2eb7b commit 79c68f8

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,30 @@ void importer::addEntryToLookupTable(SwiftLookupTable &table,
18691869
if (shouldSuppressDeclImport(named))
18701870
return;
18711871

1872+
// Leave incomplete struct/enum/union types out of the table; Swift only
1873+
// handles pointers to them.
1874+
// FIXME: At some point we probably want to be importing incomplete types,
1875+
// so that pointers to different incomplete types themselves have distinct
1876+
// types. At that time it will be necessary to make the decision of whether
1877+
// or not to import an incomplete type declaration based on whether it's
1878+
// actually the struct backing a CF type:
1879+
//
1880+
// typedef struct CGColor *CGColorRef;
1881+
//
1882+
// The best way to do this is probably to change CFDatabase.def to include
1883+
// struct names when relevant, not just pointer names. That way we can check
1884+
// both CFDatabase.def and the objc_bridge attribute and cover all our bases.
1885+
if (auto *tagDecl = dyn_cast<clang::TagDecl>(named)) {
1886+
// We add entries for ClassTemplateSpecializations that don't have
1887+
// definition. It's possible that the decl will be instantiated by
1888+
// SwiftDeclConverter later on. We cannot force instantiating
1889+
// ClassTemplateSPecializations here because we're currently writing the
1890+
// AST, so we cannot modify it.
1891+
if (!isa<clang::ClassTemplateSpecializationDecl>(named) &&
1892+
!tagDecl->getDefinition()) {
1893+
return;
1894+
}
1895+
}
18721896
// If we have a name to import as, add this entry to the table.
18731897
auto currentVersion =
18741898
ImportNameVersion::fromOptions(nameImporter.getLangOpts());

test/Interop/Cxx/class/invalid-class-errors.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ module Test {
99
}
1010

1111
//--- Inputs/test.h
12-
struct X;
13-
1412
struct A {
1513
A(const A&) = delete;
1614
};
@@ -23,9 +21,6 @@ struct __attribute__((swift_attr("import_unsafe"))) B {
2321

2422
import Test
2523

26-
// CHECK: note: record 'X' is not defined (incomplete)
27-
public func test(x: X) { }
28-
2924
// CHECK: note: record 'A' is not automatically importable: does not have a copy constructor or destructor. Refer to the C++ Interop User Manual to classify this type.
3025
public func test(x: A) { }
3126
// CHECK: note: record 'B' is not automatically importable: does not have a copy constructor or destructor. Refer to the C++ Interop User Manual to classify this type.

0 commit comments

Comments
 (0)