Skip to content

Commit 88f118e

Browse files
committed
Fixed the parsing of functions with integral template args.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent eaf6a8e commit 88f118e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Generator/Passes/SymbolsCodeGenerator.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Globalization;
23
using System.Linq;
34
using System.Text;
45
using CppSharp.AST;
@@ -241,7 +242,20 @@ private string GetFunctionName(Function function, string @namespace)
241242
string.Empty : (@namespace + "::"))}{function.OriginalName}{
242243
(function.SpecializationInfo == null ? string.Empty : $@"<{
243244
string.Join(", ", function.SpecializationInfo.Arguments.Select(
244-
a => a.Type.Visit(cppTypePrinter)))}>")}";
245+
a =>
246+
{
247+
switch (a.Kind)
248+
{
249+
case TemplateArgument.ArgumentKind.Type:
250+
return a.Type.Visit(cppTypePrinter);
251+
case TemplateArgument.ArgumentKind.Declaration:
252+
return a.Declaration.Visit(cppTypePrinter);
253+
case TemplateArgument.ArgumentKind.Integral:
254+
return a.Integral.ToString(CultureInfo.InvariantCulture);
255+
}
256+
throw new System.ArgumentOutOfRangeException(
257+
nameof(a.Kind), a.Kind, "Unsupported kind of template argument.");
258+
}))}>")}";
245259
}
246260

247261
private void WriteRedeclaration(Function function, string returnType,

tests/CSharp/CSharpTemplates.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,12 @@ std::map<int, int> usesValidSpecialisationOfIgnoredTemplate();
691691

692692
DLL_API DependentValueFields<double> specialiseReturnOnly();
693693

694+
template <int Size> void* qbswap(const void *source, size_t count, void *dest) noexcept;
695+
template<> inline void* qbswap<1>(const void *source, size_t count, void *dest) noexcept
696+
{
697+
return 0;
698+
}
699+
694700
// force the symbols for the template instantiations because we do not have the auto-compilation for the generated C++ source
695701
template class DLL_API IndependentFields<int>;
696702
template class DLL_API IndependentFields<bool>;

0 commit comments

Comments
 (0)