Skip to content

Commit 0715522

Browse files
committed
[cxx-interop] Check for simple destructors when checking value semantics
hasDestroyTypeOperations() does not account for the scenario where decl has an implicit destructor that has not yet been materialized (i.e., using clang::Sema::{Declare,Define}ImplicitDestructor()). This can sometimes happen to a type Foo if we check the value semantics of, say, std::vector<Foo> (which recursively checks the value semantics of Foo without first importing Foo). rdar://162539654
1 parent 61f9f62 commit 0715522

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8292,6 +8292,9 @@ static bool hasMoveTypeOperations(const clang::CXXRecordDecl *decl) {
82928292
}
82938293

82948294
static bool hasDestroyTypeOperations(const clang::CXXRecordDecl *decl) {
8295+
if (decl->hasSimpleDestructor())
8296+
return true;
8297+
82958298
if (auto dtor = decl->getDestructor()) {
82968299
if (dtor->isDeleted() || dtor->isIneligibleOrNotSelected() ||
82978300
dtor->getAccess() != clang::AS_public) {

test/Interop/Cxx/class/noncopyable-typechecker.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ struct SWIFT_NONCOPYABLE NonCopyableNonMovable { // expected-note {{record 'NonC
7979
NonCopyableNonMovable(NonCopyableNonMovable&& other) = delete;
8080
};
8181

82+
template<typename T> struct SWIFT_COPYABLE_IF(T) DisposableContainer {};
83+
struct POD { int x; float y; }; // special members are implicit, but should be copyable
84+
using DisposablePOD = DisposableContainer<POD>; // should also be copyable
8285

8386
//--- test.swift
8487
import Test
@@ -129,3 +132,7 @@ func missingLifetimeOperation() {
129132
let s = NonCopyableNonMovable() // expected-error {{cannot find 'NonCopyableNonMovable' in scope}}
130133
takeCopyable(s)
131134
}
135+
136+
func copyableDisposablePOD(p: DisposablePOD) {
137+
takeCopyable(p)
138+
}

0 commit comments

Comments
 (0)