Skip to content

Commit 3066bd6

Browse files
committed
Revert "[cxx-interop] Check the presence of copy constructor correctly"
This reverts commit fbbec48 The change was causing regressions in certain build configs that need to be investigated. rdar://139723218
1 parent f802b67 commit 3066bd6

File tree

4 files changed

+8
-45
lines changed

4 files changed

+8
-45
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7652,26 +7652,18 @@ static bool hasCopyTypeOperations(const clang::CXXRecordDecl *decl) {
76527652
if (decl->isInStdNamespace() && decl->getIdentifier() &&
76537653
decl->getName() == "_Optional_construct_base")
76547654
return true;
7655-
// Hack for std::vector::const_iterator from libstdc++, which uses an extra
7656-
// parameter on its copy constructor, which has a defaulted enable_if value.
7657-
auto namespaceContext = dyn_cast_or_null<clang::NamespaceDecl>(
7658-
decl->getEnclosingNamespaceContext());
7659-
if (namespaceContext && namespaceContext->getIdentifier() &&
7660-
namespaceContext->getName() == "__gnu_cxx" && decl->getIdentifier() &&
7661-
decl->getName() == "__normal_iterator")
7662-
return true;
7663-
// Hack for certain build configurations of SwiftCompilerSources
7664-
// (rdar://138924133).
7665-
if (decl->getIdentifier() && decl->getName() == "BridgedSwiftObject")
7666-
return true;
76677655

76687656
// If we have no way of copying the type we can't import the class
76697657
// at all because we cannot express the correct semantics as a swift
76707658
// struct.
7671-
return llvm::any_of(decl->ctors(), [](clang::CXXConstructorDecl *ctor) {
7672-
return ctor->isCopyConstructor() && !ctor->isDeleted() &&
7673-
ctor->getAccess() == clang::AccessSpecifier::AS_public;
7674-
});
7659+
if (llvm::any_of(decl->ctors(), [](clang::CXXConstructorDecl *ctor) {
7660+
return ctor->isCopyConstructor() &&
7661+
(ctor->isDeleted() || ctor->getAccess() != clang::AS_public);
7662+
}))
7663+
return false;
7664+
7665+
// TODO: this should probably check to make sure we actually have a copy ctor.
7666+
return true;
76757667
}
76767668

76777669
static bool hasMoveTypeOperations(const clang::CXXRecordDecl *decl) {

test/Interop/Cxx/class/Inputs/constructors.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,6 @@ struct TemplatedConstructorWithExtraArg {
7171
TemplatedConstructorWithExtraArg(T value, U other) { }
7272
};
7373

74-
struct TemplatedCopyConstructor {
75-
int x = 0;
76-
77-
TemplatedCopyConstructor(int x) : x(x) {}
78-
79-
template <class T>
80-
TemplatedCopyConstructor(const T &value) : x(value.x) {}
81-
};
82-
83-
struct TemplatedCopyConstructorWithExtraArg {
84-
int x = 0;
85-
86-
TemplatedCopyConstructorWithExtraArg(int x) : x(x) {}
87-
88-
template <class T>
89-
TemplatedCopyConstructorWithExtraArg(const T &value, int add = 0)
90-
: x(value.x + add) {}
91-
};
92-
9374
struct __attribute__((swift_attr("import_unsafe")))
9475
HasUserProvidedCopyConstructor {
9576
int numCopies;
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// RUN: %target-swift-ide-test -print-module -module-to-print=Constructors -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
22

3-
// CHECK: struct TemplatedCopyConstructor
4-
// CHECK: struct TemplatedCopyConstructorWithExtraArg
5-
63
// Make sure we don't import non-copyable types because we will have no way to
74
// represent and copy/move these in swift with correct semantics.
85
// CHECK-NOT: DeletedCopyConstructor

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import Constructors
44

5-
func takesCopyable<T: Copyable>(_ x: T.Type) {}
6-
75
let explicit = ExplicitDefaultConstructor()
86

97
let implicit = ImplicitDefaultConstructor()
@@ -14,8 +12,3 @@ let onlyCopyAndMove = CopyAndMoveConstructor() // expected-warning {{'init()' is
1412
let deletedExplicitly = DefaultConstructorDeleted() // expected-error {{missing argument for parameter 'a' in call}}
1513

1614
let withArg = ConstructorWithParam(42)
17-
18-
let _ = TemplatedCopyConstructor(123)
19-
let _ = TemplatedCopyConstructorWithExtraArg(123)
20-
takesCopyable(TemplatedCopyConstructor.self)
21-
takesCopyable(TemplatedCopyConstructorWithExtraArg.self)

0 commit comments

Comments
 (0)