Fix pointless warnings 330 for empty template instantiations

Appearing recently since 8c8e27d246.
Fixes warnings in test cases:
complextest, li_std_pair_extra, std_containers, template_nested_typemaps

Also attempts to instantiate a template for an unsupported nested template class
now have a separate new warning number 331 (SWIGWARN_PARSE_TEMPLATE_NESTED).

Closes #2965
This commit is contained in:
William S Fulton 2024-07-19 09:13:07 +01:00
parent 2dc94292a0
commit be03cd4176
7 changed files with 32 additions and 7 deletions

View File

@ -415,7 +415,8 @@ example.i(4) : Syntax error in input(1).
<li>327. Extern template ignored.
<li>328. Value assigned to <em>name</em> not used due to limited parsing implementation.
<li>329. Using declaration '<em>name</em>' for inheriting constructors uses base '<em>name</em>' which is not an immediate base of '<em>name</em>'.
<li>330. Template forward class instantiation '<em>templ</em>' with name '<em>name</em>' is ineffective.
<li>330. Template forward class '<em>name</em>' cannot be used to instantiate a full template class with name '<em>name</em>'.
<li>331. Unsupported template nested class '<em>name</em>' cannot be used to instantiate a full template class with name '<em>name</em>'.
<li>340. Lambda expressions and closures are not fully supported yet.
<li>344. Unable to deduce decltype for '<em>expr</em>'.
<li>345. Unable to deduce auto return type for '<em>name</em>' (ignored).

View File

@ -0,0 +1,15 @@
%module xxx
namespace ns {
class OuterClass {
public:
template <class T> struct Inner1 {
};
Inner1<int> useInner1(const Inner1<int>& inner) { return inner; }
#ifdef SWIG
%template(T_OuterClassInner1Double) Inner1<double>;
#endif
int iii;
};
}

View File

@ -0,0 +1,2 @@
cpp_nested_class_template.i:7: Warning 325: Nested struct not currently supported (Inner1 ignored)
cpp_nested_class_template.i:11: Warning 331: Unsupported template nested class 'ns::OuterClass::Inner1< double >' cannot be used to instantiate a full template class with name 'T_OuterClassInner1Double'.

View File

@ -1,4 +1,4 @@
cpp_template_forward.i:6: Warning 330: Template forward class instantiation 'Space::ForwardDeclaredTemplate< double >' with name 'ForwardDeclaredTemplate_double' is ineffective.
cpp_template_forward.i:9: Warning 330: Template forward class instantiation 'Space::ForwardDeclaredSpecialized< int >' with name 'ForwardDeclaredTemplate_int' is ineffective.
cpp_template_forward.i:10: Warning 330: Template forward class instantiation 'Space::ForwardDeclaredSpecialized< double >' with name 'ForwardDeclaredTemplate_double' is ineffective.
cpp_template_forward.i:16: Warning 330: Template forward class instantiation 'Space::ForwardDeclaredMisplacedPrimary< double >' with name 'ForwardDeclaredTemplate_double' is ineffective.
cpp_template_forward.i:6: Warning 330: Template forward class 'Space::ForwardDeclaredTemplate< double >' cannot be used to instantiate a full template class with name 'ForwardDeclaredTemplate_double'.
cpp_template_forward.i:9: Warning 330: Template forward class 'Space::ForwardDeclaredSpecialized< int >' cannot be used to instantiate a full template class with name 'ForwardDeclaredTemplate_int'.
cpp_template_forward.i:10: Warning 330: Template forward class 'Space::ForwardDeclaredSpecialized< double >' cannot be used to instantiate a full template class with name 'ForwardDeclaredTemplate_double'.
cpp_template_forward.i:16: Warning 330: Template forward class 'Space::ForwardDeclaredMisplacedPrimary< double >' cannot be used to instantiate a full template class with name 'ForwardDeclaredTemplate_double'.

View File

@ -4,6 +4,8 @@
#if !defined(SWIGCSHARP) && !defined(SWIGJAVA)
#pragma SWIG nowarn=SWIGWARN_PARSE_NAMED_NESTED_CLASS
%warnfilter(SWIGWARN_PARSE_TEMPLATE_NESTED) ns::OuterClass::Inner1;
%warnfilter(SWIGWARN_PARSE_TEMPLATE_NESTED) ns::OuterClass::Inner2;
#endif
namespace ns {

View File

@ -1242,6 +1242,7 @@ static Node *nested_forward_declaration(const String *storage, const String *kin
Setattr(n, "name", sname);
Setattr(n, "storage", storage);
Setattr(n, "sym:weak", "1");
SetFlag(n, "nested:forward");
add_symbols(n);
nn = n;
}
@ -2960,10 +2961,13 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
}
add_symbols_copy(templnode);
if (Equal(nodeType(templnode), "classforward")) {
if (Equal(nodeType(templnode), "classforward") && !(GetFlag(templnode, "feature:ignore") || GetFlag(templnode, "hidden"))) {
SWIG_WARN_NODE_BEGIN(templnode);
/* A full template class definition is required in order to wrap a template class as a proxy class so this %template is ineffective. */
Swig_warning(WARN_PARSE_TEMPLATE_FORWARD, cparse_file, cparse_line, "Template forward class instantiation '%s' with name '%s' is ineffective.\n", Swig_name_decl(templnode), Getattr(templnode, "sym:name"));
if (GetFlag(templnode, "nested:forward"))
Swig_warning(WARN_PARSE_TEMPLATE_NESTED, cparse_file, cparse_line, "Unsupported template nested class '%s' cannot be used to instantiate a full template class with name '%s'.\n", Swig_name_decl(templnode), Getattr(templnode, "sym:name"));
else
Swig_warning(WARN_PARSE_TEMPLATE_FORWARD, cparse_file, cparse_line, "Template forward class '%s' cannot be used to instantiate a full template class with name '%s'.\n", Swig_name_decl(templnode), Getattr(templnode, "sym:name"));
SWIG_WARN_NODE_END(templnode);
}

View File

@ -97,6 +97,7 @@
#define WARN_PARSE_ASSIGNED_VALUE 328
#define WARN_PARSE_USING_CONSTRUCTOR 329
#define WARN_PARSE_TEMPLATE_FORWARD 330
#define WARN_PARSE_TEMPLATE_NESTED 331
#define WARN_CPP11_LAMBDA 340
/* Unused since 3.0.11: #define WARN_CPP11_ALIAS_DECLARATION 341 */