Skip to content

Commit e345ebd

Browse files
committed
[cxx-interop] Disambiguate template instantiations with enum parameters
This makes sure that different class template instantiations with enum arguments get distinct generated Swift type names. Similar to aa6804a. rdar://139437761 / resolves #77358
1 parent fa8852b commit e345ebd

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

lib/ClangImporter/ClangClassTemplateNamePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct TemplateInstantiationNamePrinter
6464
return "_";
6565
}
6666

67-
std::string VisitRecordType(const clang::RecordType *type) {
67+
std::string VisitTagType(const clang::TagType *type) {
6868
auto tagDecl = type->getAsTagDecl();
6969
if (auto namedArg = dyn_cast_or_null<clang::NamedDecl>(tagDecl)) {
7070
if (auto typeDefDecl = tagDecl->getTypedefNameForAnonDecl())
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_WITH_ENUM_PARAMETER_H
2+
#define TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_WITH_ENUM_PARAMETER_H
3+
4+
template <class T>
5+
struct Wrapper {
6+
T t;
7+
};
8+
9+
enum MyEnum { MyEnum_a, MyEnum_b };
10+
enum class MyEnumClass { a, b };
11+
typedef enum { MyTypedefEnum_a, MyTypedefEnum_b } MyTypedefEnum;
12+
13+
typedef Wrapper<MyEnum> WrappedEnum;
14+
typedef Wrapper<MyEnumClass> WrappedEnumClass;
15+
typedef Wrapper<MyTypedefEnum> WrappedTypedefEnum;
16+
17+
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_WITH_ENUM_PARAMETER_H

test/Interop/Cxx/templates/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ module ClassTemplateWithPrimitiveArgument {
88
requires cplusplus
99
}
1010

11+
module ClassTemplateWithEnumParameter {
12+
header "class-template-with-enum-parameter.h"
13+
requires cplusplus
14+
}
15+
1116
module ClassTemplateWithFunctionParameter {
1217
header "class-template-with-function-parameter.h"
1318
requires cplusplus
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=ClassTemplateWithEnumParameter -I %S/Inputs -source-filename=x -cxx-interoperability-mode=upcoming-swift | %FileCheck %s
2+
3+
// CHECK: typealias WrappedEnum = Wrapper<MyEnum>
4+
// CHECK: typealias WrappedEnumClass = Wrapper<MyEnumClass>
5+
// CHECK: typealias WrappedTypedefEnum = Wrapper<MyTypedefEnum>

0 commit comments

Comments
 (0)