diff --git a/Examples/test-suite/java/template_nested_typemaps_runme.java b/Examples/test-suite/java/template_nested_typemaps_runme.java index 8e2354a8b..3bd8aa1df 100644 --- a/Examples/test-suite/java/template_nested_typemaps_runme.java +++ b/Examples/test-suite/java/template_nested_typemaps_runme.java @@ -22,6 +22,16 @@ public class template_nested_typemaps_runme { if (template_nested_typemaps.globalInt1(v) != v) throw new RuntimeException("failed"); if (template_nested_typemaps.globalInt2(v) != v) throw new RuntimeException("failed"); } + + { + short v = 88; + short vTypemap = -77; + if (b.methodShort1(v) != v) throw new RuntimeException("failed"); + if (b.methodShort2(v) != vTypemap) throw new RuntimeException("failed"); + + if (template_nested_typemaps.globalShort1(v) != v) throw new RuntimeException("failed"); + if (template_nested_typemaps.globalShort2(v) != v) throw new RuntimeException("failed"); + } } } diff --git a/Examples/test-suite/template_nested_typemaps.i b/Examples/test-suite/template_nested_typemaps.i index 273b4b0cf..8ed02eaea 100644 --- a/Examples/test-suite/template_nested_typemaps.i +++ b/Examples/test-suite/template_nested_typemaps.i @@ -1,3 +1,5 @@ +#pragma SWIG nowarn=SWIGWARN_PARSE_NESTED_TEMPLATE + %module template_nested_typemaps template struct Typemap { @@ -5,9 +7,15 @@ template struct Typemap { $1 = -99; } }; +template <> struct Typemap { + %typemap(in) short { + $1 = -77; + } +}; %inline %{ int globalInt1(int s) { return s; } +short globalShort1(short s) { return s; } template struct Breeze { int methodInt1(int s) { return s; } @@ -16,9 +24,16 @@ template struct Breeze { #endif int methodInt2(int s) { return s; } // only this method should pick up the typemap within Typemap void takeIt(T t) {} + + short methodShort1(short s) { return s; } +#if defined(SWIG) + %template(TypemapShort) Typemap; // should issue warning SWIGWARN_PARSE_NESTED_TEMPLATE +#endif + short methodShort2(short s) { return s; } // only this method should pick up the typemap within Typemap - note specialization }; int globalInt2(int s) { return s; } +short globalShort2(short s) { return s; } %} %template(BreezeString) Breeze; diff --git a/Examples/test-suite/template_partial_specialization.i b/Examples/test-suite/template_partial_specialization.i index 76bfa00fc..a81bc47a5 100644 --- a/Examples/test-suite/template_partial_specialization.i +++ b/Examples/test-suite/template_partial_specialization.i @@ -119,14 +119,10 @@ template struct ThreeParm { void a3( //} %} -#if 0 -struct AA { // crashes -#else namespace AA { // thinks X is in AA namespace %template(X2) X; }; #endif -#endif #if 0 namespace Space { diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index eeda3b0ea..4d4401572 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -535,6 +535,8 @@ static void add_symbols_copy(Node *n) { add_oldname = Getattr(n,"sym:name"); if ((add_oldname) || (Getattr(n,"sym:needs_symtab"))) { + int old_inclass = -1; + Node *old_current_class = 0; if (add_oldname) { DohIncref(add_oldname); /* Disable this, it prevents %rename to work with templates */ @@ -564,7 +566,9 @@ static void add_symbols_copy(Node *n) { Namespaceprefix = Swig_symbol_qualifiedscopename(0); } if (strcmp(cnodeType,"class") == 0) { + old_inclass = inclass; inclass = 1; + old_current_class = current_class; current_class = n; if (Strcmp(Getattr(n,"kind"),"class") == 0) { cplus_mode = CPLUS_PRIVATE; @@ -591,8 +595,8 @@ static void add_symbols_copy(Node *n) { add_oldname = 0; } if (strcmp(cnodeType,"class") == 0) { - inclass = 0; - current_class = 0; + inclass = old_inclass; + current_class = old_current_class; } } else { if (strcmp(cnodeType,"extend") == 0) { @@ -2752,7 +2756,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va } else { Setattr(templnode,"sym:typename","1"); } - if ($3) { + if ($3 && !inclass) { /* Comment this out for 1.3.28. We need to re-enable it later but first we need to @@ -2770,8 +2774,11 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Swig_cparse_template_expand(templnode,nname,temparms,tscope); Setattr(templnode,"sym:name",nname); Delete(nname); - Setattr(templnode,"feature:onlychildren", - "typemap,typemapitem,typemapcopy,typedef,types,fragment"); + Setattr(templnode,"feature:onlychildren", "typemap,typemapitem,typemapcopy,typedef,types,fragment"); + + if ($3) { + Swig_warning(WARN_PARSE_NESTED_TEMPLATE, cparse_file, cparse_line, "Named nested template instantiations not supported. Processing as if no name was given to %%template().\n"); + } } Delattr(templnode,"templatetype"); Setattr(templnode,"template",nn);