File tree Expand file tree Collapse file tree 4 files changed +36
-8
lines changed Expand file tree Collapse file tree 4 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -7718,17 +7718,16 @@ static bool hasCopyTypeOperations(const clang::CXXRecordDecl *decl) {
7718
7718
decl->getName () == " _Optional_construct_base" )
7719
7719
return true ;
7720
7720
7721
+ if (decl->hasSimpleCopyConstructor ())
7722
+ return true ;
7723
+
7721
7724
// If we have no way of copying the type we can't import the class
7722
7725
// at all because we cannot express the correct semantics as a swift
7723
7726
// struct.
7724
- if (llvm::any_of (decl->ctors (), [](clang::CXXConstructorDecl *ctor) {
7725
- return ctor->isCopyConstructor () &&
7726
- (ctor->isDeleted () || ctor->getAccess () != clang::AS_public);
7727
- }))
7728
- return false ;
7729
-
7730
- // TODO: this should probably check to make sure we actually have a copy ctor.
7731
- return true ;
7727
+ return llvm::any_of (decl->ctors (), [](clang::CXXConstructorDecl *ctor) {
7728
+ return ctor->isCopyConstructor () && !ctor->isDeleted () &&
7729
+ ctor->getAccess () == clang::AccessSpecifier::AS_public;
7730
+ });
7732
7731
}
7733
7732
7734
7733
static bool hasMoveTypeOperations (const clang::CXXRecordDecl *decl) {
Original file line number Diff line number Diff line change @@ -71,6 +71,25 @@ struct TemplatedConstructorWithExtraArg {
71
71
TemplatedConstructorWithExtraArg (T value, U other) { }
72
72
};
73
73
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
+
74
93
struct __attribute__ ((swift_attr(" import_unsafe" )))
75
94
HasUserProvidedCopyConstructor {
76
95
int numCopies;
Original file line number Diff line number Diff line change 1
1
// RUN: %target-swift-ide-test -print-module -module-to-print=Constructors -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2
2
3
+ // CHECK: struct TemplatedCopyConstructor
4
+ // CHECK: struct TemplatedCopyConstructorWithExtraArg
5
+
3
6
// Make sure we don't import non-copyable types because we will have no way to
4
7
// represent and copy/move these in swift with correct semantics.
5
8
// CHECK-NOT: DeletedCopyConstructor
Original file line number Diff line number Diff line change 2
2
3
3
import Constructors
4
4
5
+ func takesCopyable< T: Copyable > ( _ x: T . Type ) { }
6
+
5
7
let explicit = ExplicitDefaultConstructor ( )
6
8
7
9
let implicit = ImplicitDefaultConstructor ( )
@@ -12,3 +14,8 @@ let onlyCopyAndMove = CopyAndMoveConstructor() // expected-warning {{'init()' is
12
14
let deletedExplicitly = DefaultConstructorDeleted ( ) // expected-error {{missing argument for parameter 'a' in call}}
13
15
14
16
let withArg = ConstructorWithParam ( 42 )
17
+
18
+ let _ = TemplatedCopyConstructor ( 123 )
19
+ let _ = TemplatedCopyConstructorWithExtraArg ( 123 )
20
+ takesCopyable ( TemplatedCopyConstructor . self)
21
+ takesCopyable ( TemplatedCopyConstructorWithExtraArg . self)
You can’t perform that action at this time.
0 commit comments