You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using AnnotatedOwnsNonCopyable =AnnotatedOwnsT<NonCopyable>;
41
+
42
+
template <typename F, typename S>
43
+
struct SWIFT_COPYABLE_IF(F, S) MyPair {
44
+
F first;
45
+
S second;
46
+
};
47
+
48
+
MyPair<int,NonCopyable> p1();
49
+
MyPair<int,NonCopyable*> p2();
50
+
MyPair<int,OwnsNonCopyable> p3();
51
+
MyPair<int,AnnotatedOwnsNonCopyable> p4();
52
+
MyPair<int,MyPair<int,NonCopyable>> p5();
53
+
MyPair<NonCopyable,int> p6();
54
+
31
55
#if __cplusplus >= 202002L
32
56
template<typename T>
33
57
struct RequiresCopyableT {
@@ -38,6 +62,9 @@ struct RequiresCopyableT {
38
62
};
39
63
40
64
using NonCopyableRequires =RequiresCopyableT<NonCopyable>;
65
+
using CopyableIfRequires = RequiresCopyableT<MyPair<int, NonCopyable>>;
66
+
67
+
MyPair<int,NonCopyableRequires> p7();
41
68
42
69
#endif
43
70
@@ -55,9 +82,28 @@ func userDefinedTypes() {
55
82
takeCopyable(ownsT) // no error, OwnsNonCopyable imported as Copyable
56
83
}
57
84
85
+
func useCopyableIf(){
86
+
takeCopyable(p1()) // expected-error {{global function 'takeCopyable' requires that 'MyPair<CInt, NonCopyable>' conform to 'Copyable'}}
87
+
takeCopyable(p2())
88
+
89
+
// p3() -> MyPair<int, OwnsNonCopyable> is imported as Copyable and will cause an error during IRGen.
90
+
// During typecheck we don't produce an error because we're missing an annotation in OwnsT.
91
+
takeCopyable(p3())
92
+
// p4() -> (MyPair<int, AnnotatedOwnsNonCopyable>) is imported as NonCopyable because AnnotatedOwnsT is correctly annotated.
93
+
takeCopyable(p4()) // expected-error {{global function 'takeCopyable' requires that 'MyPair<CInt, AnnotatedOwnsT<NonCopyable>>' conform to 'Copyable'}}
94
+
95
+
takeCopyable(p5()) // expected-error {{global function 'takeCopyable' requires that 'MyPair<CInt, MyPair<CInt, NonCopyable>>' conform to 'Copyable'}}
96
+
takeCopyable(p6()) // expected-error {{global function 'takeCopyable' requires that 'MyPair<NonCopyable, CInt>' conform to 'Copyable'}}
97
+
}
98
+
58
99
#if CPP20
59
100
func useOfRequires(){
60
-
letnCop=NonCopyableRequires()
61
-
takeCopyable(nCop) // expected-cpp20-error {{global function 'takeCopyable' requires that 'NonCopyableRequires' (aka 'RequiresCopyableT<NonCopyable>') conform to 'Copyable'}}
101
+
leta=NonCopyableRequires()
102
+
takeCopyable(a) // expected-cpp20-error {{global function 'takeCopyable' requires that 'NonCopyableRequires' (aka 'RequiresCopyableT<NonCopyable>') conform to 'Copyable'}}
103
+
104
+
letb=CopyableIfRequires()
105
+
takeCopyable(b) // expected-cpp20-error {{global function 'takeCopyable' requires that 'CopyableIfRequires' (aka 'RequiresCopyableT<MyPair<CInt, NonCopyable>>') conform to 'Copyable'}}
106
+
107
+
takeCopyable(p7()) // expected-cpp20-error {{global function 'takeCopyable' requires that 'MyPair<CInt, RequiresCopyableT<NonCopyable>>' conform to 'Copyable'}}
0 commit comments