Skip to content

Commit 8cc45dd

Browse files
authored
Merge pull request #84105 from Xazax-hun/no-vwt-for-anon-types
[cxx-interop] Basic support for anonymous structs with non-copyable fields
2 parents 5f67a9a + 0c909a8 commit 8cc45dd

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3112,11 +3112,12 @@ namespace {
31123112
}
31133113
}
31143114
}
3115-
if (copyCtor && !isExplicitlyNonCopyable) {
3115+
if (copyCtor && !isExplicitlyNonCopyable &&
3116+
!decl->isAnonymousStructOrUnion()) {
31163117
clangSema.DefineImplicitCopyConstructor(clang::SourceLocation(),
31173118
copyCtor);
31183119
}
3119-
if (moveCtor) {
3120+
if (moveCtor && !decl->isAnonymousStructOrUnion()) {
31203121
clangSema.DefineImplicitMoveConstructor(clang::SourceLocation(),
31213122
moveCtor);
31223123
}

lib/IRGen/GenMeta.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6940,6 +6940,10 @@ namespace {
69406940
}
69416941

69426942
void addValueWitnessTable() {
6943+
if (auto cd = Target->getClangDecl())
6944+
if (auto rd = dyn_cast<clang::RecordDecl>(cd))
6945+
if (rd->isAnonymousStructOrUnion())
6946+
return;
69436947
auto vwtPointer = emitValueWitnessTable(/*relative*/ false).getValue();
69446948
B.addSignedPointer(vwtPointer,
69456949
IGM.getOptions().PointerAuth.ValueWitnessTable,

test/Interop/Cxx/class/move-only/Inputs/move-only-cxx-value-type.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,16 @@ struct NonCopyableHolderDerivedDerived: NonCopyableHolderDerived {
5656
inline NonCopyable *getNonCopyablePtr() { return nullptr; }
5757
inline NonCopyableDerived *getNonCopyableDerivedPtr() { return nullptr; }
5858

59+
template <typename T>
60+
struct FieldInAnonStruct {
61+
FieldInAnonStruct() : field(5) {}
62+
FieldInAnonStruct(const FieldInAnonStruct &) = delete;
63+
FieldInAnonStruct(FieldInAnonStruct &&) = default;
64+
struct {
65+
T field;
66+
};
67+
};
68+
69+
using FieldInAnonStructNC = FieldInAnonStruct<NonCopyable>;
70+
5971
#endif // TEST_INTEROP_CXX_CLASS_MOVE_ONLY_VT_H

test/Interop/Cxx/class/move-only/move-only-cxx-value-type.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ MoveOnlyCxxValueType.test("Test move only field access in derived holder") {
7070
expectEqual(c.x.x, 5)
7171
}
7272

73+
MoveOnlyCxxValueType.test("Test move only field in anonymous struct") {
74+
let a = FieldInAnonStructNC()
75+
let b = a
76+
}
7377
runAllTests()

0 commit comments

Comments
 (0)