mirror of https://github.com/swig/swig
Fix incomplete ignoring of duplicating %template instantiations
When template parameter typedefs are involved, a duplicate %template instantiation was not properly ignoring the duplicate instantiation, resulting in compile time errors. Closes #2814
This commit is contained in:
parent
72626f4871
commit
ce911f8ae3
|
@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.2.1 (24 Feb 2024)
|
||||
===========================
|
||||
|
||||
2024-02-23: wsfulton
|
||||
#2814 Correctly ignore duplicate template instantiation (when the
|
||||
duplicate contains typedef'd template parameters).
|
||||
|
||||
2024-02-22: erezgeva
|
||||
[Ruby, Octave, R] #2284 Fix segfault shrinking STL containers.
|
||||
|
||||
|
|
|
@ -463,6 +463,7 @@ CPP_TEST_CASES += \
|
|||
template_default_inherit \
|
||||
template_default_qualify \
|
||||
template_default_vw \
|
||||
template_duplicate \
|
||||
template_empty_inherit \
|
||||
template_enum \
|
||||
template_enum_ns_inherit \
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
%module xxx
|
||||
|
||||
%include <std_vector.i>
|
||||
|
||||
// Note these 404 warnings come from two different places in the SWIG code base
|
||||
|
||||
%inline %{
|
||||
typedef unsigned char uint8_T;
|
||||
typedef unsigned char boolean_T;
|
||||
%}
|
||||
|
||||
%template(std_vector_boolean_type) std::vector<boolean_T>;
|
||||
%template(std_vector_boolean_type_duplicate) std::vector<boolean_T>;
|
||||
%template(std_vector_uint8_type) std::vector<uint8_T>;
|
||||
|
||||
namespace std {
|
||||
%template(std_vector_boolean_type_again) vector<boolean_T>;
|
||||
%template(std_vector_uint8_type_again) vector<uint8_T>;
|
||||
%template(std_vector_unsigned_char) vector<unsigned char>;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
cpp_template_duplicate.i:13: Warning 404: Duplicate template instantiation of 'vector< boolean_T >' with name 'std_vector_boolean_type_duplicate' ignored,
|
||||
cpp_template_duplicate.i:12: Warning 404: previous instantiation of 'vector< boolean_T >' with name 'std_vector_boolean_type'.
|
||||
cpp_template_duplicate.i:17: Warning 404: Duplicate template instantiation of 'vector< boolean_T >' with name 'std_vector_boolean_type_again' ignored,
|
||||
cpp_template_duplicate.i:12: Warning 404: previous instantiation of 'vector< boolean_T >' with name 'std_vector_boolean_type'.
|
||||
cpp_template_duplicate.i:18: Warning 404: Duplicate template instantiation of 'vector< uint8_T >' with name 'std_vector_uint8_type_again' ignored,
|
||||
cpp_template_duplicate.i:14: Warning 404: previous instantiation of 'vector< uint8_T >' with name 'std_vector_uint8_type'.
|
||||
cpp_template_duplicate.i:12: Warning 404: Duplicate template instantiation of 'vector< boolean_T >' with name 'std_vector_boolean_type' ignored,
|
||||
cpp_template_duplicate.i:19: Warning 404: previous instantiation of 'vector< unsigned char >' with name 'std_vector_unsigned_char'.
|
||||
cpp_template_duplicate.i:14: Warning 404: Duplicate template instantiation of 'vector< uint8_T >' with name 'std_vector_uint8_type' ignored,
|
||||
cpp_template_duplicate.i:19: Warning 404: previous instantiation of 'vector< unsigned char >' with name 'std_vector_unsigned_char'.
|
|
@ -0,0 +1,21 @@
|
|||
%module template_duplicate
|
||||
|
||||
%include <std_vector.i>
|
||||
|
||||
%warnfilter(SWIGWARN_TYPE_REDEFINED) std::vector<boolean_T>;
|
||||
%warnfilter(SWIGWARN_TYPE_REDEFINED) std::vector<uint8_T>;
|
||||
|
||||
%inline %{
|
||||
typedef unsigned char uint8_T;
|
||||
typedef unsigned char boolean_T;
|
||||
%}
|
||||
|
||||
%template(std_vector_boolean_type) std::vector<boolean_T>;
|
||||
%template(std_vector_boolean_type_duplicate) std::vector<boolean_T>;
|
||||
%template(std_vector_uint8_type) std::vector<uint8_T>;
|
||||
|
||||
namespace std {
|
||||
%template(std_vector_boolean_type_again) vector<boolean_T>;
|
||||
%template(std_vector_uint8_type_again) vector<uint8_T>;
|
||||
%template(std_vector_unsigned_char) vector<unsigned char>;
|
||||
}
|
|
@ -442,9 +442,10 @@ class TypePass:private Dispatcher {
|
|||
SwigType_typedef_class(fname);
|
||||
scopename = Copy(fname);
|
||||
} else {
|
||||
// Does this code ever get executed ??
|
||||
Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n), "Template '%s' was already wrapped,\n", SwigType_namestr(name));
|
||||
Swig_warning(WARN_TYPE_REDEFINED, Getfile(cn), Getline(cn), "previous wrap of '%s'.\n", SwigType_namestr(Getattr(cn, "name")));
|
||||
// Arguably the parser should instead ignore these duplicate template instantiations, in particular for ensuring the first parsed instantiation is used
|
||||
SetFlag(n, "feature:ignore");
|
||||
Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n), "Duplicate template instantiation of '%s' with name '%s' ignored,\n", SwigType_namestr(name), Getattr(n, "sym:name"));
|
||||
Swig_warning(WARN_TYPE_REDEFINED, Getfile(cn), Getline(cn), "previous instantiation of '%s' with name '%s'.\n", SwigType_namestr(Getattr(cn, "name")), Getattr(cn, "sym:name"));
|
||||
scopename = 0;
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue