Add new warning if an empty template declaration is used on a base class, minor docs improvement for empty template declarations.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13840 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-09-14 22:25:35 +00:00
commit bc43673a86
6 changed files with 37 additions and 7 deletions

View file

@ -4,6 +4,19 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.9 (in progress)
===========================
2012-09-14: wsfulton
Add new warning if the empty template instantiation is used as a base class, for example:
template <typename T> class Base {};
%template() Base<int>;
class Derived : public Base<int> {};
gives the following warning instead of silently ignoring the base:
cpp_inherit.i:52: Warning 401: Base class 'Base< int >' has no name as it is an empty template instantiated with '%template()'. Ignored.
cpp_inherit.i:51: Warning 401: The %template directive must be written before 'Base< int >' is used as a base class and be declared with a name.
2012-09-11: wsfulton
[Java] Fix #3535304 - Direct use of a weak global reference in directors
sometimes causing seg faults especially on Android.

View file

@ -3121,8 +3121,8 @@ nothing is known about <tt>List&lt;int&gt;</tt>, you will get a warning message
<div class="shell">
<pre>
example.h:42. Nothing known about class 'List&lt;int &gt;' (ignored).
example.h:42. Maybe you forgot to instantiate 'List&lt;int &gt;' using %template.
example.h:42: Warning 401. Nothing known about class 'List&lt;int &gt;'. Ignored.
example.h:42: Warning 401. Maybe you forgot to instantiate 'List&lt;int &gt;' using %template.
</pre>
</div>
@ -3163,7 +3163,7 @@ Don't worry--if you get the order wrong, SWIG should generate a warning message.
Occasionally, you may need to tell SWIG about base classes that are defined by templates,
but which aren't supposed to be wrapped. Since SWIG is not able to automatically
instantiate templates for this purpose, you must do it manually. To do this, simply
use <tt>%template</tt> with no name. For example:
use the empty template instantiation, that is, <tt>%template</tt> with no name. For example:
</p>
<div class="code">

View file

@ -45,3 +45,11 @@ struct Recursive : Recursive
{
};
%}
template <typename T> class Base {};
%template() Base<int>;
class Derived : public Base<int> {};
class Derived2 : public Base<double> {};
%template(BaseDouble) Base<double>;

View file

@ -268,6 +268,10 @@ cpp_inherit.i:24: Warning 401: Nothing known about base class 'A6'. Ignored.
cpp_inherit.i:26: Warning 401: Nothing known about base class 'A7< int >'. Ignored.
cpp_inherit.i:26: Warning 401: Maybe you forgot to instantiate 'A7< int >' using %template.
cpp_inherit.i:45: Warning 323: Recursive scope inheritance of 'Recursive'.
cpp_inherit.i:52: Warning 401: Base class 'Base< int >' has no name as it is an empty template instantiated with '%template()'. Ignored.
cpp_inherit.i:51: Warning 401: The %template directive must be written before 'Base< int >' is used as a base class and be declared with a name.
cpp_inherit.i:53: Warning 401: Base class 'Base< double >' undefined.
cpp_inherit.i:54: Warning 401: 'Base< double >' must be defined before it is used as a base class.
:::::::::::::::::::::::::::::::: cpp_macro_locator.i :::::::::::::::::::::::::::::::::::
cpp_macro_locator.i:66: Warning 204: CPP #warning, "inline warning message one".

View file

@ -965,7 +965,7 @@ int Language::cDeclaration(Node *n) {
DohIncref(type);
Setattr(n, "type", ty);
if (GetFlag(n, "feature:onlychildren") && !GetFlag(n, "feature:ignore")) {
// Found an unignored templated method that has a an empty template instantiation (%template())
// Found an unignored templated method that has an empty template instantiation (%template())
// Ignore it unless it has been %rename'd
if (Strncmp(symname, "__dummy_", 8) == 0) {
SetFlag(n, "feature:ignore");

View file

@ -185,9 +185,14 @@ class TypePass:private Dispatcher {
bcls = 0;
} else {
if (Getattr(bcls, "typepass:visit")) {
if (!ilist)
ilist = alist = NewList();
Append(ilist, bcls);
if (!Getattr(bcls, "feature:onlychildren")) {
if (!ilist)
ilist = alist = NewList();
Append(ilist, bcls);
} else {
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));
}
} 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(bcls), Getline(bcls), "'%s' must be defined before it is used as a base class.\n", SwigType_namestr(bname));