Fix incorrectly shown warning for empty template instantiation used as a base class.

This commit is contained in:
William S Fulton 2017-08-02 22:55:23 +01:00
commit 2165f27f5d
4 changed files with 47 additions and 4 deletions

View file

@ -12,6 +12,14 @@ Version 4.0.0 (in progress)
after template<T>). Fixes https://github.com/swig/swig/issues/1031 after template<T>). Fixes https://github.com/swig/swig/issues/1031
reported by Artem V L. reported by Artem V L.
2017-08-02: wsfulton
Fix incorrectly shown warning when an empty template instantiation was used on a
class used as a base class and that base class was explicitly ignored with %ignore.
Example of the warning which will no longer appear:
Warning 401: Base class 'Functor< int,int >' has no name as it is an empty
template instantiated with '%template()'. Ignored.
2017-07-17: fflexo 2017-07-17: fflexo
[Java] #674 Add std_list.i to add support for std::list containers. The Java proxy [Java] #674 Add std_list.i to add support for std::list containers. The Java proxy
extends java.util.AbstractSequentialList and makes the C++ std::list container look extends java.util.AbstractSequentialList and makes the C++ std::list container look

View file

@ -418,6 +418,7 @@ CPP_TEST_CASES += \
template_default_inherit \ template_default_inherit \
template_default_qualify \ template_default_qualify \
template_default_vw \ template_default_vw \
template_empty_inherit \
template_enum \ template_enum \
template_enum_ns_inherit \ template_enum_ns_inherit \
template_enum_typedef \ template_enum_typedef \

View file

@ -0,0 +1,30 @@
%module template_empty_inherit
%inline %{
template<class Arg, typename Result> struct Functor {
virtual Result operator()(Arg x) const = 0;
};
%}
// Bug fix - %ignore was resulting in this warning:
// Warning 401: Base class 'Functor< int,int >' has no name as it is an empty template instantiated with '%template()'. Ignored.
%ignore Functor<int, int>;
%template() Functor<int, int>;
%inline %{
#include <algorithm>
struct SquareFunctor : Functor<int, int> {
int operator()(int v) const { return v*v; }
};
%}
%include <std_vector.i>
%template(VectorInt) std::vector<int>;
%inline %{
std::vector<int> squares(const std::vector<int>& vi) {
std::vector<int> result;
std::transform(vi.begin(), vi.end(), std::back_inserter(result), SquareFunctor());
return result;
}
%}

View file

@ -187,10 +187,12 @@ class TypePass:private Dispatcher {
ilist = alist = NewList(); ilist = alist = NewList();
Append(ilist, bcls); Append(ilist, bcls);
} else { } else {
if (!GetFlag(bcls, "feature:ignore")) {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname)); Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname)); Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
} }
} }
}
break; break;
} }
if (Strcmp(nodeType(bcls), "classforward") != 0) { if (Strcmp(nodeType(bcls), "classforward") != 0) {
@ -209,9 +211,11 @@ class TypePass:private Dispatcher {
ilist = alist = NewList(); ilist = alist = NewList();
Append(ilist, bcls); Append(ilist, bcls);
} else { } else {
if (!GetFlag(bcls, "feature:ignore")) {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname)); Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname)); Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
} }
}
} else { } else {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' undefined.\n", SwigType_namestr(bname)); Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' undefined.\n", SwigType_namestr(bname));
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "'%s' must be defined before it is used as a base class.\n", SwigType_namestr(bname)); Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "'%s' must be defined before it is used as a base class.\n", SwigType_namestr(bname));