mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Revert "[cxx-interop] Implicitly defined move constructors"
This reverts commit c3cd9939c1.
This commit is contained in:
@@ -3132,13 +3132,14 @@ namespace {
|
||||
// instantiate its copy constructor.
|
||||
bool isExplicitlyNonCopyable = hasNonCopyableAttr(decl);
|
||||
|
||||
clang::CXXConstructorDecl *moveCtor = nullptr;
|
||||
clang::CXXConstructorDecl *defaultCtor = nullptr;
|
||||
if (decl->needsImplicitCopyConstructor() && !isExplicitlyNonCopyable) {
|
||||
clangSema.DeclareImplicitCopyConstructor(
|
||||
const_cast<clang::CXXRecordDecl *>(decl));
|
||||
}
|
||||
if (decl->needsImplicitMoveConstructor()) {
|
||||
clangSema.DeclareImplicitMoveConstructor(
|
||||
moveCtor = clangSema.DeclareImplicitMoveConstructor(
|
||||
const_cast<clang::CXXRecordDecl *>(decl));
|
||||
}
|
||||
if (decl->needsImplicitDefaultConstructor()) {
|
||||
@@ -3155,13 +3156,20 @@ namespace {
|
||||
// Note: we use "doesThisDeclarationHaveABody" here because
|
||||
// that's what "DefineImplicitCopyConstructor" checks.
|
||||
!declCtor->doesThisDeclarationHaveABody()) {
|
||||
if (declCtor->isDefaultConstructor()) {
|
||||
if (declCtor->isMoveConstructor()) {
|
||||
if (!moveCtor)
|
||||
moveCtor = declCtor;
|
||||
} else if (declCtor->isDefaultConstructor()) {
|
||||
if (!defaultCtor)
|
||||
defaultCtor = declCtor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (moveCtor && !decl->isAnonymousStructOrUnion()) {
|
||||
clangSema.DefineImplicitMoveConstructor(clang::SourceLocation(),
|
||||
moveCtor);
|
||||
}
|
||||
if (defaultCtor) {
|
||||
clangSema.DefineImplicitDefaultConstructor(clang::SourceLocation(),
|
||||
defaultCtor);
|
||||
@@ -3170,8 +3178,7 @@ namespace {
|
||||
if (decl->needsImplicitDestructor()) {
|
||||
auto dtor = clangSema.DeclareImplicitDestructor(
|
||||
const_cast<clang::CXXRecordDecl *>(decl));
|
||||
if (!dtor->isDeleted() && !dtor->isIneligibleOrNotSelected())
|
||||
clangSema.DefineImplicitDestructor(clang::SourceLocation(), dtor);
|
||||
clangSema.DefineImplicitDestructor(clang::SourceLocation(), dtor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -611,7 +611,7 @@ namespace {
|
||||
/*invocation subs*/ SubstitutionMap(), IGF.IGM.Context);
|
||||
}
|
||||
|
||||
void emitCopyWithCopyOrMoveConstructor(
|
||||
void emitCopyWithCopyConstructor(
|
||||
IRGenFunction &IGF, SILType T,
|
||||
const clang::CXXConstructorDecl *copyConstructor, llvm::Value *src,
|
||||
llvm::Value *dest) const {
|
||||
@@ -625,21 +625,12 @@ namespace {
|
||||
if (copyConstructor->isDefaulted() &&
|
||||
copyConstructor->getAccess() == clang::AS_public &&
|
||||
!copyConstructor->isDeleted() &&
|
||||
!copyConstructor->isIneligibleOrNotSelected() &&
|
||||
// Note: we use "doesThisDeclarationHaveABody" here because
|
||||
// that's what "DefineImplicitCopyConstructor" checks.
|
||||
!copyConstructor->doesThisDeclarationHaveABody()) {
|
||||
assert(!copyConstructor->getParent()->isAnonymousStructOrUnion() &&
|
||||
"Cannot do codegen of special member functions of anonymous "
|
||||
"structs/unions");
|
||||
if (copyConstructor->isCopyConstructor())
|
||||
importer->getClangSema().DefineImplicitCopyConstructor(
|
||||
clang::SourceLocation(),
|
||||
const_cast<clang::CXXConstructorDecl *>(copyConstructor));
|
||||
else
|
||||
importer->getClangSema().DefineImplicitMoveConstructor(
|
||||
clang::SourceLocation(),
|
||||
const_cast<clang::CXXConstructorDecl *>(copyConstructor));
|
||||
importer->getClangSema().DefineImplicitCopyConstructor(
|
||||
clang::SourceLocation(),
|
||||
const_cast<clang::CXXConstructorDecl *>(copyConstructor));
|
||||
}
|
||||
|
||||
auto &diagEngine = importer->getClangSema().getDiagnostics();
|
||||
@@ -821,9 +812,9 @@ namespace {
|
||||
Address srcAddr, SILType T,
|
||||
bool isOutlined) const override {
|
||||
if (auto copyConstructor = findCopyConstructor()) {
|
||||
emitCopyWithCopyOrMoveConstructor(IGF, T, copyConstructor,
|
||||
srcAddr.getAddress(),
|
||||
destAddr.getAddress());
|
||||
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
|
||||
srcAddr.getAddress(),
|
||||
destAddr.getAddress());
|
||||
return;
|
||||
}
|
||||
StructTypeInfoBase<AddressOnlyCXXClangRecordTypeInfo, FixedTypeInfo,
|
||||
@@ -836,9 +827,9 @@ namespace {
|
||||
SILType T, bool isOutlined) const override {
|
||||
if (auto copyConstructor = findCopyConstructor()) {
|
||||
destroy(IGF, destAddr, T, isOutlined);
|
||||
emitCopyWithCopyOrMoveConstructor(IGF, T, copyConstructor,
|
||||
srcAddr.getAddress(),
|
||||
destAddr.getAddress());
|
||||
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
|
||||
srcAddr.getAddress(),
|
||||
destAddr.getAddress());
|
||||
return;
|
||||
}
|
||||
StructTypeInfoBase<AddressOnlyCXXClangRecordTypeInfo, FixedTypeInfo,
|
||||
@@ -850,15 +841,17 @@ namespace {
|
||||
SILType T, bool isOutlined,
|
||||
bool zeroizeIfSensitive) const override {
|
||||
if (auto moveConstructor = findMoveConstructor()) {
|
||||
emitCopyWithCopyOrMoveConstructor(IGF, T, moveConstructor,
|
||||
src.getAddress(), dest.getAddress());
|
||||
emitCopyWithCopyConstructor(IGF, T, moveConstructor,
|
||||
src.getAddress(),
|
||||
dest.getAddress());
|
||||
destroy(IGF, src, T, isOutlined);
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto copyConstructor = findCopyConstructor()) {
|
||||
emitCopyWithCopyOrMoveConstructor(IGF, T, copyConstructor,
|
||||
src.getAddress(), dest.getAddress());
|
||||
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
|
||||
src.getAddress(),
|
||||
dest.getAddress());
|
||||
destroy(IGF, src, T, isOutlined);
|
||||
return;
|
||||
}
|
||||
@@ -872,16 +865,18 @@ namespace {
|
||||
bool isOutlined) const override {
|
||||
if (auto moveConstructor = findMoveConstructor()) {
|
||||
destroy(IGF, dest, T, isOutlined);
|
||||
emitCopyWithCopyOrMoveConstructor(IGF, T, moveConstructor,
|
||||
src.getAddress(), dest.getAddress());
|
||||
emitCopyWithCopyConstructor(IGF, T, moveConstructor,
|
||||
src.getAddress(),
|
||||
dest.getAddress());
|
||||
destroy(IGF, src, T, isOutlined);
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto copyConstructor = findCopyConstructor()) {
|
||||
destroy(IGF, dest, T, isOutlined);
|
||||
emitCopyWithCopyOrMoveConstructor(IGF, T, copyConstructor,
|
||||
src.getAddress(), dest.getAddress());
|
||||
emitCopyWithCopyConstructor(IGF, T, copyConstructor,
|
||||
src.getAddress(),
|
||||
dest.getAddress());
|
||||
destroy(IGF, src, T, isOutlined);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,9 +99,3 @@ module CustomSmartPtr {
|
||||
requires cplusplus
|
||||
export *
|
||||
}
|
||||
|
||||
module StdExpected {
|
||||
header "std-expected.h"
|
||||
requires cplusplus
|
||||
export *
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_UNIQUE_PTR_H
|
||||
#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_UNIQUE_PTR_H
|
||||
|
||||
#include <memory>
|
||||
#include <expected>
|
||||
|
||||
using NonCopyableExpected = std::expected<std::unique_ptr<bool>, int>;
|
||||
|
||||
template<typename T>
|
||||
class UniqueRef {
|
||||
public:
|
||||
std::unique_ptr<T> _field;
|
||||
};
|
||||
|
||||
struct Decoder {};
|
||||
enum Error {
|
||||
DoomA,
|
||||
DoomB
|
||||
};
|
||||
|
||||
using DecoderOrError = std::expected<UniqueRef<Decoder>, Error>;
|
||||
|
||||
#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_UNIQUE_PTR_H
|
||||
@@ -1,24 +0,0 @@
|
||||
// RUN: not %target-swift-frontend %s -typecheck -I %S/Inputs -cxx-interoperability-mode=default -Xcc -std=c++23 -diagnostic-style llvm 2>&1 | %FileCheck %s
|
||||
|
||||
// TODO <expected> not yet supported with libstdc++
|
||||
|
||||
// rdar://164027738
|
||||
// UNSUPPORTED: OS=linux-gnu
|
||||
|
||||
// https://github.com/apple/swift/issues/70226
|
||||
// UNSUPPORTED: OS=windows-msvc
|
||||
|
||||
import StdExpected
|
||||
import CxxStdlib
|
||||
|
||||
func takeCopyable<T: Copyable>(_ x: T) {}
|
||||
|
||||
let nonCopExpected = NonCopyableExpected()
|
||||
takeCopyable(nonCopExpected)
|
||||
// CHECK: error: global function 'takeCopyable' requires that 'NonCopyableExpected' (aka {{.*}}) conform to 'Copyable'
|
||||
|
||||
let doe = DecoderOrError()
|
||||
takeCopyable(doe)
|
||||
// CHECK: error: global function 'takeCopyable' requires that 'DecoderOrError' (aka {{.*}}) conform to 'Copyable'
|
||||
|
||||
// CHECK-NOT: error
|
||||
Reference in New Issue
Block a user