Browse Source

Use TemplatedDecl.Parameters cuz Class.TemplateParameters may not be available at this point

refactor
josetr 3 years ago
parent
commit
0d92eaef16
  1. 7
      src/Generator/Generators/C/CppTypePrinter.cs
  2. 19
      tests/CSharp/CSharpTemplates.h

7
src/Generator/Generators/C/CppTypePrinter.cs

@ -5,6 +5,7 @@ using System.Linq; @@ -5,6 +5,7 @@ using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators.CSharp;
using CppSharp.Passes;
using CppSharp.Types;
namespace CppSharp.Generators.C
@ -577,11 +578,11 @@ namespace CppSharp.Generators.C @@ -577,11 +578,11 @@ namespace CppSharp.Generators.C
args.Add(arg.Declaration.Visit(this));
break;
case TemplateArgument.ArgumentKind.Integral:
Class template = specialization.TemplatedDecl.TemplatedClass;
var nonTypeTemplateParameter = template.TemplateParameters[i]
ClassTemplate template = specialization.TemplatedDecl;
var nonTypeTemplateParameter = template.Parameters[i]
as NonTypeTemplateParameter;
if (!(nonTypeTemplateParameter?.DefaultArgument is
BuiltinTypeExpressionObsolete builtinExpression) ||
BuiltinTypeExpressionObsolete builtinExpression) ||
builtinExpression.Value != arg.Integral)
{
args.Add(arg.Integral.ToString(CultureInfo.InvariantCulture));

19
tests/CSharp/CSharpTemplates.h

@ -944,3 +944,22 @@ public: @@ -944,3 +944,22 @@ public:
};
const FloatArrayF<6> I6{ 1., 1., 1., 0., 0., 0. };
// KEEP ORDER OTHERWISE TEST WONT WORK
namespace IncompleteClassTemplatesTests
{
template <size_t Size>
struct StructSizeT {};
template <typename T>
struct StructT
{
template<typename U>
struct Inc { };
};
struct Instantiation
{
StructT<StructSizeT<4000>> st;
};
}
Loading…
Cancel
Save