mirror of https://github.com/swig/swig
Fix using declarations and templates with explicitly declared constructors
Corner case problem fix for when the base template class was
instantiated with %template including the default arguments and
the base class had an explicitly declared constructor.
Swig_symbol_template_deftype() was sometimes incorrectly finding
a constructor instead of a template and thus failing to correctly
expand the template default args. Problem noticed since
9cf049186b
where constructors are
stored simply by their name instead of name plus template args.
Probably fixes a few other subtle template problems when a template
class contains default args.
This commit is contained in:
parent
30e68625af
commit
b7332ce8ca
|
@ -473,6 +473,7 @@ CPP_TEST_CASES += \
|
||||||
template_namespace_forward_declaration \
|
template_namespace_forward_declaration \
|
||||||
template_using_directive_and_declaration_forward \
|
template_using_directive_and_declaration_forward \
|
||||||
template_using_directive_typedef \
|
template_using_directive_typedef \
|
||||||
|
template_using_member_default_arg \
|
||||||
template_nested \
|
template_nested \
|
||||||
template_nested_flat \
|
template_nested_flat \
|
||||||
template_nested_typemaps \
|
template_nested_typemaps \
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
import template_using_member_default_arg.*;
|
||||||
|
|
||||||
|
public class template_using_member_default_arg_runme {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("template_using_member_default_arg");
|
||||||
|
} 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[]) {
|
||||||
|
ThingADerivedInt a = new ThingADerivedInt();
|
||||||
|
a.describeA();
|
||||||
|
ThingBDerivedInt b = new ThingBDerivedInt();
|
||||||
|
b.describeB();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
from template_using_member_default_arg import *
|
||||||
|
|
||||||
|
a = ThingADerivedInt()
|
||||||
|
a.describeA()
|
||||||
|
b = ThingBDerivedInt()
|
||||||
|
b.describeB()
|
|
@ -0,0 +1,33 @@
|
||||||
|
%module template_using_member_default_arg
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
template<typename T1, typename T2 = short>
|
||||||
|
struct ThingA {
|
||||||
|
ThingA() {}
|
||||||
|
protected:
|
||||||
|
void describeA() {}
|
||||||
|
};
|
||||||
|
template<typename T1, typename T2 = short>
|
||||||
|
struct ThingB {
|
||||||
|
ThingB() {}
|
||||||
|
protected:
|
||||||
|
void describeB() {}
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
template<typename T1>
|
||||||
|
struct ThingADerived : ThingA<T1> {
|
||||||
|
using ThingA<T1>::describeA;
|
||||||
|
};
|
||||||
|
template<typename T1>
|
||||||
|
struct ThingBDerived : ThingB<T1> {
|
||||||
|
using ThingB<T1>::describeB;
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
%template(ThingAInt) ThingA<int>; // was okay
|
||||||
|
%template(ThingADerivedInt) ThingADerived<int>;
|
||||||
|
|
||||||
|
%template(ThingBInt) ThingB<int, short>; // was failing - using directive in this template was not found
|
||||||
|
%template(ThingBDerivedInt) ThingBDerived<int>;
|
|
@ -553,6 +553,12 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
|
||||||
String *cname = NewString(name);
|
String *cname = NewString(name);
|
||||||
String *dname = Swig_symbol_template_deftype(cname, 0);
|
String *dname = Swig_symbol_template_deftype(cname, 0);
|
||||||
if (!Equal(dname, name)) {
|
if (!Equal(dname, name)) {
|
||||||
|
/* Add another symbol with all template default arguments expanded, eg
|
||||||
|
*
|
||||||
|
* template <typename T1, typename T2 = short> struct X {};
|
||||||
|
* %template(XInt) X<int>;
|
||||||
|
*
|
||||||
|
* then name=X<int>, and dname=X<int,short> so add X<int,short> here too. */
|
||||||
Swig_symbol_cadd(dname, n);
|
Swig_symbol_cadd(dname, n);
|
||||||
}
|
}
|
||||||
Delete(dname);
|
Delete(dname);
|
||||||
|
@ -1589,6 +1595,10 @@ static int symbol_no_constructor(Node *n) {
|
||||||
return !Checkattr(n, "nodeType", "constructor");
|
return !Checkattr(n, "nodeType", "constructor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int symbol_is_template(Node *n) {
|
||||||
|
return Checkattr(n, "nodeType", "template");
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Swig_symbol_type_qualify()
|
* Swig_symbol_type_qualify()
|
||||||
*
|
*
|
||||||
|
@ -1944,6 +1954,7 @@ ParmList *Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope,
|
||||||
* Swig_symbol_template_deftype()
|
* Swig_symbol_template_deftype()
|
||||||
*
|
*
|
||||||
* Apply default args to generic template type
|
* Apply default args to generic template type
|
||||||
|
* Return input type with template args expanded to include default template args
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#define SWIG_TEMPLATE_DEFTYPE_CACHE
|
#define SWIG_TEMPLATE_DEFTYPE_CACHE
|
||||||
|
@ -2018,9 +2029,9 @@ SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) {
|
||||||
String *targs = SwigType_templateargs(base);
|
String *targs = SwigType_templateargs(base);
|
||||||
String *tsuffix = SwigType_templatesuffix(base);
|
String *tsuffix = SwigType_templatesuffix(base);
|
||||||
ParmList *tparms = SwigType_function_parms(targs, 0);
|
ParmList *tparms = SwigType_function_parms(targs, 0);
|
||||||
Node *tempn = Swig_symbol_clookup_local(tprefix, tscope);
|
Node *tempn = Swig_symbol_clookup_local_check(tprefix, tscope, symbol_is_template);
|
||||||
if (!tempn && tsuffix && Len(tsuffix)) {
|
if (!tempn && tsuffix && Len(tsuffix)) {
|
||||||
tempn = Swig_symbol_clookup(tprefix, 0);
|
tempn = Swig_symbol_clookup_check(tprefix, 0, symbol_is_template);
|
||||||
}
|
}
|
||||||
#ifdef SWIG_DEBUG
|
#ifdef SWIG_DEBUG
|
||||||
Printf(stderr, "deftype type %s %s %d\n", e, tprefix, (long) tempn);
|
Printf(stderr, "deftype type %s %s %d\n", e, tprefix, (long) tempn);
|
||||||
|
|
Loading…
Reference in New Issue