File tree Expand file tree Collapse file tree 4 files changed +33
-0
lines changed
test/Interop/Cxx/reference Expand file tree Collapse file tree 4 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -1863,6 +1863,17 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
1863
1863
dyn_cast<clang::TemplateTypeParmType>(clangDecl->getReturnType ())) {
1864
1864
importedType = {findGenericTypeInGenericDecls (templateType, genericParams),
1865
1865
false };
1866
+ } else if ((isa<clang::PointerType>(clangDecl->getReturnType ()) ||
1867
+ isa<clang::ReferenceType>(clangDecl->getReturnType ())) &&
1868
+ isa<clang::TemplateTypeParmType>(clangDecl->getReturnType ()->getPointeeType ())) {
1869
+ auto pointeeType = clangDecl->getReturnType ()->getPointeeType ();
1870
+ auto templateParamType = cast<clang::TemplateTypeParmType>(pointeeType);
1871
+ PointerTypeKind pointerKind = pointeeType.getQualifiers ().hasConst ()
1872
+ ? PTK_UnsafePointer
1873
+ : PTK_UnsafeMutablePointer;
1874
+ auto genericType =
1875
+ findGenericTypeInGenericDecls (templateParamType, genericParams);
1876
+ importedType = {genericType->wrapInPointer (pointerKind), false };
1866
1877
} else if (!(isa<clang::RecordType>(clangDecl->getReturnType ()) ||
1867
1878
isa<clang::TemplateSpecializationType>(clangDecl->getReturnType ())) ||
1868
1879
// TODO: we currently don't lazily load operator return types, but
Original file line number Diff line number Diff line change @@ -28,4 +28,10 @@ void dontImportAtomicRef(_Atomic(int)&) { }
28
28
29
29
void takeConstRef (const int &);
30
30
31
+ template <class T >
32
+ T &refToTemplate (T &t) { return t; }
33
+
34
+ template <class T >
35
+ const T &constRefToTemplate (const T &t) { return t; }
36
+
31
37
#endif // TEST_INTEROP_CXX_REFERENCE_INPUTS_REFERENCE_H
Original file line number Diff line number Diff line change 12
12
// CHECK: func setConstStaticIntRvalueRef(_: Int32)
13
13
// CHECK: func getFuncRef() -> @convention(c) () -> Int32
14
14
// CHECK: func getFuncRvalueRef() -> @convention(c) () -> Int32
15
+ // CHECK: func refToTemplate<T>(_ t: inout T) -> UnsafeMutablePointer<T>
16
+ // CHECK: func constRefToTemplate<T>(_ t: T) -> UnsafePointer<T>
15
17
16
18
// CHECK-NOT: refToDependent
17
19
// CHECK-NOT: dontImportAtomicRef
Original file line number Diff line number Diff line change @@ -87,4 +87,18 @@ ReferenceTestSuite.test("pod-struct-const-lvalue-reference") {
87
87
expectEqual ( getStaticInt ( ) , 78 )
88
88
}
89
89
90
+ ReferenceTestSuite . test ( " reference to template " ) {
91
+ var val : CInt = 53
92
+ let ref = refToTemplate ( & val)
93
+ expectEqual ( 53 , ref. pointee)
94
+ ref. pointee = 42
95
+ expectEqual ( 42 , val)
96
+ }
97
+
98
+ ReferenceTestSuite . test ( " const reference to template " ) {
99
+ var val : CInt = 53
100
+ let ref = constRefToTemplate ( val)
101
+ expectEqual ( 53 , ref. pointee)
102
+ }
103
+
90
104
runAllTests ( )
You can’t perform that action at this time.
0 commit comments