Skip to content

Commit a2aeaed

Browse files
committed
Rename templates only used through aliases
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 0919026 commit a2aeaed

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/Generator/Passes/StripUnusedSystemTypesPass.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ private bool TryMarkType(Type desugared)
5959
var templateType = desugared as TemplateSpecializationType;
6060
if (templateType != null)
6161
{
62-
MarkAsUsed(templateType.Template);
63-
MarkAsUsed(templateType.Template.TemplatedDecl);
62+
var template = templateType.Template;
63+
if (template.TemplatedDecl is TypeAlias typeAlias &&
64+
typeAlias.Type.Desugar() is TemplateSpecializationType specializationType)
65+
{
66+
MarkAsUsed(template);
67+
MarkAsUsed(template.TemplatedDecl);
68+
template = specializationType.Template;
69+
}
70+
MarkAsUsed(template);
71+
MarkAsUsed(template.TemplatedDecl);
6472
return true;
6573
}
6674

@@ -90,6 +98,6 @@ private void RemoveUnusedStdTypes(DeclarationContext context)
9098
}
9199
}
92100

93-
private HashSet<Declaration> usedStdTypes = new HashSet<Declaration>();
101+
private readonly HashSet<Declaration> usedStdTypes = new HashSet<Declaration>();
94102
}
95103
}

src/Generator/Passes/TrimSpecializationsPass.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private static void TryMoveExternalSpecializations(Class template)
158158
let module = arg.Type.Type.GetModule()
159159
where module != null
160160
select module).ToList().TopologicalSort(m => m.Dependencies);
161-
if (modules.Any())
161+
if (modules.Count > 0)
162162
{
163163
var module = modules.Last();
164164
module.ExternalClassTemplateSpecializations.Add(specialization);

tests/NamespacesDerived/NamespacesDerived.Tests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void TestCodeGeneration()
1515
using (new DerivedFromSecondaryBaseInDependency()) { }
1616
using (var der2 = new Derived2())
1717
using (der2.LocalTypedefSpecialization) { }
18+
Assert.That(typeof(Derived2).Assembly.GetTypes().Any(t => t.FullName.Contains("Std.Vector")), Is.True);
1819
}
1920

2021
[Test]

tests/NamespacesDerived/NamespacesDerived.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ class DLL_API Ignored
109109
std::basic_string<char, std::char_traits<char>, CustomAllocator<char>> customAllocatedString;
110110
};
111111

112+
template<class T, class Alloc = CustomAllocator<T>>
113+
using vector = ::std::vector<T, Alloc>;
114+
112115
class DLL_API StdFields
113116
{
114117
private:
115-
std::vector<unsigned int, CustomAllocator<unsigned int>> customAllocatedVector;
118+
vector<unsigned int, CustomAllocator<unsigned int>> customAllocatedVector;
116119
};
117120

118121
DLL_API bool operator<<(const Base& b, const char* str);

0 commit comments

Comments
 (0)