Skip to content

Commit 8b45e33

Browse files
authored
Merge pull request #75297 from swiftlang/susmonteiro/cxx-const-types
Add _const to Swift declaration names of const types
2 parents 3eb9ad4 + 24fc755 commit 8b45e33

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lib/ClangImporter/ClangClassTemplateNamePrinter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,11 @@ std::string swift::importer::printClassTemplateSpecializationName(
148148
// Use import name here so builtin types such as "int" map to their
149149
// Swift equivalent ("CInt").
150150
if (arg.getKind() == clang::TemplateArgument::Type) {
151-
auto ty = arg.getAsType().getTypePtr();
152-
buffer << templateNamePrinter.Visit(ty);
151+
auto ty = arg.getAsType();
152+
buffer << templateNamePrinter.Visit(ty.getTypePtr());
153+
if (ty.isConstQualified()) {
154+
buffer << "_const";
155+
}
153156
return;
154157
} else if (arg.getKind() == clang::TemplateArgument::Integral) {
155158
buffer << "_";

test/Interop/Cxx/templates/Inputs/class-template-with-primitive-argument.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@ struct MagicWrapper {
77
int getValuePlusArg(int arg) const { return t + arg; }
88
};
99

10+
template<class M>
11+
struct DoubleWrapper {
12+
M m;
13+
int getValuePlusArg(int arg) const { return m.getValuePlusArg(arg); }
14+
};
15+
1016
typedef MagicWrapper<int> WrappedMagicInt;
17+
typedef MagicWrapper<const int> WrappedMagicIntConst;
18+
typedef MagicWrapper<const long> WrappedMagicLongConst;
1119
typedef MagicWrapper<int*> WrappedMagicIntPtr;
1220
typedef MagicWrapper<const int*> WrappedMagicIntConstPtr;
1321
typedef MagicWrapper<int**> WrappedMagicIntPtrPtr;
1422

23+
typedef DoubleWrapper<MagicWrapper<int>> DoubleWrappedInt;
24+
typedef DoubleWrapper<MagicWrapper<const int>> DoubleWrappedIntConst;
25+
typedef DoubleWrapper<MagicWrapper<const long>> DoubleWrappedLongConst;
26+
typedef DoubleWrapper<MagicWrapper<int*>> DoubleWrappedIntPtr;
27+
typedef DoubleWrapper<MagicWrapper<const int*>> DoubleWrappedIntConstPtr;
28+
1529
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_WITH_PRIMITIVE_ARGUMENT_H

test/Interop/Cxx/templates/class-template-with-primitive-argument-module-interface.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44
// CHECK: struct MagicWrapper<T> {
55
// CHECK: }
66

7+
// CHECK: struct DoubleWrapper<M> {
8+
// CHECK: }
9+
710
// CHECK: typealias WrappedMagicInt = MagicWrapper<CInt>
11+
// CHECK: typealias WrappedMagicIntConst = MagicWrapper<CInt_const>
12+
// CHECK: typealias WrappedMagicLongConst = MagicWrapper<CLong_const>
813
// CHECK: typealias WrappedMagicIntPtr = MagicWrapper<UnsafeMutablePointer<CInt>>
914
// CHECK: typealias WrappedMagicIntConstPtr = MagicWrapper<UnsafePointer<CInt>>
1015
// CHECK: typealias WrappedMagicIntPtrPtr = MagicWrapper<UnsafeMutablePointer<UnsafeMutablePointer<CInt>>>
16+
17+
// CHECK: typealias DoubleWrappedInt = DoubleWrapper<MagicWrapper<CInt>>
18+
// CHECK: typealias DoubleWrappedIntConst = DoubleWrapper<MagicWrapper<CInt_const>>
19+
// CHECK: typealias DoubleWrappedLongConst = DoubleWrapper<MagicWrapper<CLong_const>>
20+
// CHECK: typealias DoubleWrappedIntPtr = DoubleWrapper<MagicWrapper<UnsafeMutablePointer<CInt>>>
21+
// CHECK: typealias DoubleWrappedIntConstPtr = DoubleWrapper<MagicWrapper<UnsafePointer<CInt>>>

0 commit comments

Comments
 (0)