Fix deduction of partially specialized template parameters

when the specialized parameter is non-trivial, used in a wrapped method
and the type to %template uses typedefs. For example:

  typedef double & DoubleRef;
  template <typename T> struct XX {};
  template <typename T> struct XX<T &> { void fn(T t) {} };
  %template(XXD) XX<DoubleRef>;

The type of the parameter in the instantiated template for fn is now correctly deduced
as double.
This commit is contained in:
William S Fulton 2023-01-14 23:40:02 +00:00
parent cac16bf94d
commit bd2de6fc06
4 changed files with 43 additions and 25 deletions

View File

@ -11,6 +11,19 @@ Version 4.2.0 (in progress)
#2492 [python] Fix unused parameter warnings for self parameter in
generated C/C++ wrapper code.
2023-01-14: wsfulton
Fix deduction of partially specialized template parameters when the specialized
parameter is non-trivial, used in a wrapped method and the type to %template uses
typedefs. For example:
typedef double & DoubleRef;
template <typename T> struct XX {};
template <typename T> struct XX<T &> { void fn(T t) {} };
%template(XXD) XX<DoubleRef>;
The type of the parameter in the instantiated template for fn is now correctly deduced
as double.
2023-01-03: wsfulton
#983 Fix seg fault when instantiating templates with parameters that are function
parameters containing templates, such as:

View File

@ -12,12 +12,15 @@ public class template_partial_specialization_typedef_runme {
}
public static void main(String argv[]) {
double dub = 11.1;
Concrete concrete = new Concrete();
// One parameter tests
new A().a();
new B().b();
new C().c();
new D().d();
new E().e();
new B().b(); new B().bb(dub);
new C().c(); new C().cc(dub);
new D().d(); new D().dd(dub);
new E().e(); new E().ee(dub);
new F().f();
new G().g();
@ -28,10 +31,10 @@ public class template_partial_specialization_typedef_runme {
new M().m();
new N().n();
new BB().b();
new BBB().b();
new BBBB().b();
new BBBBB().b();
new BB().b(); new BB().bb(true);
new BBB().b(); new BBB().bb('A');
new BBBB().b(); new BBBB().bb((short)12);
new BBBBB().b(); new BBBBB().bb(123);
new B1().b();
new B2().b();
@ -40,18 +43,18 @@ public class template_partial_specialization_typedef_runme {
// Two parameter tests
new A_().a();
new B_().b();
new C_().c();
new D_().d();
new B_().b(); new B_().bbb(dub);
new C_().c(); new C_().ccc(dub);
new D_().d(); new D_().ddd(123);
new E_().e();
new F_().f();
new G_().g();
new C1_().c();
new C2_().c();
new C3_().c();
new C4_().c();
new B1_().b();
new C1_().c(); new C1_().ccc(concrete);
new C2_().c(); new C2_().ccc(concrete);
new C3_().c(); new C3_().ccc(concrete);
new C4_().c(); new C4_().ccc(concrete);
new B1_().b(); new B1_().bbb(concrete);
new E1_().e();
new E2_().e();
}

View File

@ -30,10 +30,10 @@ namespace TypeDef {
}
namespace One {
template <typename T> struct OneParm { void a() {} };
template <typename T> struct OneParm<T *> { void b() {} };
template <typename T> struct OneParm<T &> { void c() {} };
template <typename T> struct OneParm<T const &> { void d() {} };
template <typename T> struct OneParm<T * const &> { void e() {} };
template <typename T> struct OneParm<T *> { void b() {} void bb(const T &t) {} };
template <typename T> struct OneParm<T &> { void c() {} void cc(const T &t) {} };
template <typename T> struct OneParm<T const &> { void d() {} void dd(const T &t) {} };
template <typename T> struct OneParm<T * const &> { void e() {} void ee(const T &t) {} };
template <> struct OneParm<int> { void f() {} };
template <> struct OneParm<int * const &> { void g() {} };
@ -90,10 +90,10 @@ namespace One {
struct Concrete {};
namespace Two {
template <typename T1, typename T2> struct TwoParm { void a() {} };
template <typename T1, typename T2> struct TwoParm<T1 *, T2 *> { void b() {} };
template <typename T1, typename T2> struct TwoParm<T1 *, const T2 *> { void c() {} };
template <typename T1, typename T2> struct TwoParm<const T1 *, const T2 *> { void d() {} };
template <typename T1> struct TwoParm<T1 *, int *> { void e() {} };
template <typename T1, typename T2> struct TwoParm<T1 *, T2 *> { void b() {} void bbb(const T2 &t) {} };
template <typename T1, typename T2> struct TwoParm<T1 *, const T2 *> { void c() {} void ccc(const T2 &t) {} };
template <typename T1, typename T2> struct TwoParm<const T1 *, const T2 *> { void d() {} void ddd(const T2 &t) {} };
template <typename T1> struct TwoParm<T1 *, int *> { void e() {} /*void eee(const T1 &t) {} TODO */};
template <typename T1> struct TwoParm<T1, int> { void f() {} };
template <> struct TwoParm<int *, const int *> { void g() {} };
}

View File

@ -452,10 +452,12 @@ int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab
ptype = Getattr(p, "type");
tptype = Getattr(tp, "type");
if (ptype && tptype) {
partial_type = partial_arg(tptype, ptype);
SwigType *ty = Swig_symbol_typedef_reduce(tptype, tscope);
partial_type = partial_arg(ty, ptype);
/* Printf(stdout,"partial '%s' '%s' ---> '%s'\n", tptype, ptype, partial_type); */
Setattr(tp, "type", partial_type);
Delete(partial_type);
Delete(ty);
}
p = nextSibling(p);
tp = nextSibling(tp);