Skip to content

Add _const to Swift declaration names of const types #75297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/ClangImporter/ClangClassTemplateNamePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ std::string swift::importer::printClassTemplateSpecializationName(
// Use import name here so builtin types such as "int" map to their
// Swift equivalent ("CInt").
if (arg.getKind() == clang::TemplateArgument::Type) {
auto ty = arg.getAsType().getTypePtr();
buffer << templateNamePrinter.Visit(ty);
auto ty = arg.getAsType();
buffer << templateNamePrinter.Visit(ty.getTypePtr());
if (ty.isConstQualified()) {
buffer << "_const";
}
return;
} else if (arg.getKind() == clang::TemplateArgument::Integral) {
buffer << "_";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ struct MagicWrapper {
int getValuePlusArg(int arg) const { return t + arg; }
};

template<class M>
struct DoubleWrapper {
M m;
int getValuePlusArg(int arg) const { return m.getValuePlusArg(arg); }
};

typedef MagicWrapper<int> WrappedMagicInt;
typedef MagicWrapper<const int> WrappedMagicIntConst;
typedef MagicWrapper<const long> WrappedMagicLongConst;
typedef MagicWrapper<int*> WrappedMagicIntPtr;
typedef MagicWrapper<const int*> WrappedMagicIntConstPtr;
typedef MagicWrapper<int**> WrappedMagicIntPtrPtr;

typedef DoubleWrapper<MagicWrapper<int>> DoubleWrappedInt;
typedef DoubleWrapper<MagicWrapper<const int>> DoubleWrappedIntConst;
typedef DoubleWrapper<MagicWrapper<const long>> DoubleWrappedLongConst;
typedef DoubleWrapper<MagicWrapper<int*>> DoubleWrappedIntPtr;
typedef DoubleWrapper<MagicWrapper<const int*>> DoubleWrappedIntConstPtr;

#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_WITH_PRIMITIVE_ARGUMENT_H
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
// CHECK: struct MagicWrapper<T> {
// CHECK: }

// CHECK: struct DoubleWrapper<M> {
// CHECK: }

// CHECK: typealias WrappedMagicInt = MagicWrapper<CInt>
// CHECK: typealias WrappedMagicIntConst = MagicWrapper<CInt_const>
// CHECK: typealias WrappedMagicLongConst = MagicWrapper<CLong_const>
// CHECK: typealias WrappedMagicIntPtr = MagicWrapper<UnsafeMutablePointer<CInt>>
// CHECK: typealias WrappedMagicIntConstPtr = MagicWrapper<UnsafePointer<CInt>>
// CHECK: typealias WrappedMagicIntPtrPtr = MagicWrapper<UnsafeMutablePointer<UnsafeMutablePointer<CInt>>>

// CHECK: typealias DoubleWrappedInt = DoubleWrapper<MagicWrapper<CInt>>
// CHECK: typealias DoubleWrappedIntConst = DoubleWrapper<MagicWrapper<CInt_const>>
// CHECK: typealias DoubleWrappedLongConst = DoubleWrapper<MagicWrapper<CLong_const>>
// CHECK: typealias DoubleWrappedIntPtr = DoubleWrapper<MagicWrapper<UnsafeMutablePointer<CInt>>>
// CHECK: typealias DoubleWrappedIntConstPtr = DoubleWrapper<MagicWrapper<UnsafePointer<CInt>>>