From 88f118ec4efc29ee949857fbd2de370941062290 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 25 Dec 2018 15:31:44 +0200 Subject: [PATCH] Fixed the parsing of functions with integral template args. Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/SymbolsCodeGenerator.cs | 16 +++++++++++++++- tests/CSharp/CSharpTemplates.h | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Generator/Passes/SymbolsCodeGenerator.cs b/src/Generator/Passes/SymbolsCodeGenerator.cs index 0a738399..12b723fa 100644 --- a/src/Generator/Passes/SymbolsCodeGenerator.cs +++ b/src/Generator/Passes/SymbolsCodeGenerator.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using CppSharp.AST; @@ -241,7 +242,20 @@ namespace CppSharp.Passes string.Empty : (@namespace + "::"))}{function.OriginalName}{ (function.SpecializationInfo == null ? string.Empty : $@"<{ string.Join(", ", function.SpecializationInfo.Arguments.Select( - a => a.Type.Visit(cppTypePrinter)))}>")}"; + a => + { + switch (a.Kind) + { + case TemplateArgument.ArgumentKind.Type: + return a.Type.Visit(cppTypePrinter); + case TemplateArgument.ArgumentKind.Declaration: + return a.Declaration.Visit(cppTypePrinter); + case TemplateArgument.ArgumentKind.Integral: + return a.Integral.ToString(CultureInfo.InvariantCulture); + } + throw new System.ArgumentOutOfRangeException( + nameof(a.Kind), a.Kind, "Unsupported kind of template argument."); + }))}>")}"; } private void WriteRedeclaration(Function function, string returnType, diff --git a/tests/CSharp/CSharpTemplates.h b/tests/CSharp/CSharpTemplates.h index bd3fe991..16932e22 100644 --- a/tests/CSharp/CSharpTemplates.h +++ b/tests/CSharp/CSharpTemplates.h @@ -691,6 +691,12 @@ std::map usesValidSpecialisationOfIgnoredTemplate(); DLL_API DependentValueFields specialiseReturnOnly(); +template void* qbswap(const void *source, size_t count, void *dest) noexcept; +template<> inline void* qbswap<1>(const void *source, size_t count, void *dest) noexcept +{ + return 0; +} + // force the symbols for the template instantiations because we do not have the auto-compilation for the generated C++ source template class DLL_API IndependentFields; template class DLL_API IndependentFields;