summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2023-01-14 23:40:02 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2023-02-17 08:23:41 +0000
commitbd2de6fc0604a9990dd70c2603004d3062842d9e (patch)
tree48f8100210984c3c3b50676fa10ef2e35ae04795
parentcac16bf94dc041d5f28e2e0fdfa1ae880d801d58 (diff)
downloadswig-bd2de6fc0604a9990dd70c2603004d3062842d9e.tar.gz
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.
-rw-r--r--CHANGES.current13
-rw-r--r--Examples/test-suite/java/template_partial_specialization_typedef_runme.java35
-rw-r--r--Examples/test-suite/template_partial_specialization_typedef.i16
-rw-r--r--Source/CParse/templ.c4
4 files changed, 43 insertions, 25 deletions
diff --git a/CHANGES.current b/CHANGES.current
index 62b609bc9..54813b0d3 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -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:
diff --git a/Examples/test-suite/java/template_partial_specialization_typedef_runme.java b/Examples/test-suite/java/template_partial_specialization_typedef_runme.java
index 04653cdc0..008367c7a 100644
--- a/Examples/test-suite/java/template_partial_specialization_typedef_runme.java
+++ b/Examples/test-suite/java/template_partial_specialization_typedef_runme.java
@@ -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();
}
diff --git a/Examples/test-suite/template_partial_specialization_typedef.i b/Examples/test-suite/template_partial_specialization_typedef.i
index 6f8a11591..04475da1a 100644
--- a/Examples/test-suite/template_partial_specialization_typedef.i
+++ b/Examples/test-suite/template_partial_specialization_typedef.i
@@ -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() {} };
}
diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c
index 718e5ddb8..7a4d0cf4f 100644
--- a/Source/CParse/templ.c
+++ b/Source/CParse/templ.c
@@ -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);