From 8f09d00bb0416e4aec163df15fcdcb4f58d47a7e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 6 Dec 2007 22:35:43 +0000 Subject: [PATCH] Fix template template parameters with default arguments git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10179 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 6 +++ Examples/test-suite/common.mk | 1 + .../template_template_parameters_runme.java | 28 ++++++++++++++ .../test-suite/template_template_parameters.i | 37 +++++++++++++++++++ Source/CParse/parser.y | 5 ++- 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/java/template_template_parameters_runme.java create mode 100644 Examples/test-suite/template_template_parameters.i diff --git a/CHANGES.current b/CHANGES.current index f27e8e7c4..9d7120c40 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,12 @@ Version 1.3.34 (in progress) ============================ +12/06/2007: wsfulton + Fix #1734415 - template template parameters with default arguments such as: + + template class t_alloc = pfc::alloc_fast > + class list_t : public list_impl_t > { ... }; + 12/04/2007: mgossage [lua] Fix a bug in the class hierachy code, where the methods were not propagated, if the name ordering was in a certain order. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f3421ef0a..5bbd98a20 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -299,6 +299,7 @@ CPP_TEST_CASES += \ template_specialization_enum \ template_static \ template_tbase_template \ + template_template_parameters \ template_typedef \ template_typedef_cplx \ template_typedef_cplx2 \ diff --git a/Examples/test-suite/java/template_template_parameters_runme.java b/Examples/test-suite/java/template_template_parameters_runme.java new file mode 100644 index 000000000..42135b982 --- /dev/null +++ b/Examples/test-suite/java/template_template_parameters_runme.java @@ -0,0 +1,28 @@ + + +import template_template_parameters.*; + +public class template_template_parameters_runme { + + static { + try { + System.loadLibrary("template_template_parameters"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + ListFastBool listBool = new ListFastBool(); + listBool.setItem(true); + if (listBool.getItem() != true) + throw new RuntimeException("Failed"); + + ListDefaultDouble listDouble = new ListDefaultDouble(); + listDouble.setItem(10.2); + if (listDouble.getItem() != 10.2) + throw new RuntimeException("Failed"); + } +} + diff --git a/Examples/test-suite/template_template_parameters.i b/Examples/test-suite/template_template_parameters.i new file mode 100644 index 000000000..892ba9e41 --- /dev/null +++ b/Examples/test-suite/template_template_parameters.i @@ -0,0 +1,37 @@ +%module template_template_parameters + + +%inline %{ + namespace pfc { + template class t_alloc> class array_t {}; + template class alloc_fast { + public: + typedef t_item alloc_type; + }; + } + + template class list_impl_t {}; + + template class t_alloc = pfc::alloc_fast > + class list_t : public list_impl_t > { + public: + t_item item; +// typename t_alloc::alloc_type allotype; // SWIG can't handle this yet + void xx() { + typename t_alloc::alloc_type atype; // this type is the same as t_item type + atype = 10; + } + }; + +void TestInstantiations() { + pfc::array_t myArrayInt; + list_impl_t > myListImplInt; +} +%} + +%template(ListImplFastBool) list_impl_t >; +%template(ListFastBool) list_t; + +%template(ListImplFastDouble) list_impl_t >; +%template(ListDefaultDouble) list_t; + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 161d8b4ca..67835f162 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -4432,10 +4432,13 @@ parm : rawtype parameter_declarator { } } - | TEMPLATE LESSTHAN cpptype GREATERTHAN cpptype idcolon { + | TEMPLATE LESSTHAN cpptype GREATERTHAN cpptype idcolon def_args { $$ = NewParm(NewStringf("template %s %s", $5,$6), 0); Setfile($$,cparse_file); Setline($$,cparse_line); + if ($7.val) { + Setattr($$,"value",$7.val); + } } | PERIOD PERIOD PERIOD { SwigType *t = NewString("v(...)");