Skip to content

Commit 7ac1b81

Browse files
committed
[cxx-interop] Skip forward-declared nested structs.
This prevents us from accidentially adding the same sub-type twice.
1 parent 008ce5b commit 7ac1b81

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,6 +3374,11 @@ namespace {
33743374
}
33753375

33763376
if (isa<TypeDecl>(member)) {
3377+
// Only import definitions. Otherwise, we might add the same member
3378+
// twice.
3379+
if (auto tagDecl = dyn_cast<clang::TagDecl>(nd))
3380+
if (tagDecl->getDefinition() != tagDecl)
3381+
continue;
33773382
// A struct nested inside another struct will either be logically
33783383
// a sibling of the outer struct, or contained inside of it, depending
33793384
// on if it has a declaration name or not.

test/Interop/Cxx/class/Inputs/nested-records.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ struct S10 {
4545
};
4646
};
4747

48+
struct HasForwardDeclaredNestedType {
49+
struct ForwardDeclaredType;
50+
struct NormalSubType { };
51+
struct ForwardDeclaredType { };
52+
};
53+
4854
// TODO: Nested class templates (SR-13853).
4955

5056
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_NESTED_RECORDS_H

test/Interop/Cxx/class/nested-records-module-interface.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@
5555
// CHECK: }
5656
// CHECK: }
5757
// CHECK: }
58+
59+
// CHECK: struct HasForwardDeclaredNestedType {
60+
// CHECK: struct NormalSubType {
61+
// CHECK: }
62+
// CHECK: struct ForwardDeclaredType {
63+
// CHECK: }
64+
// CHECK: }

0 commit comments

Comments
 (0)