diff --git a/CHANGES.current b/CHANGES.current index e139e0e82..f44ab054a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 7b7f444a6..b75d7fe34 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -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 \ diff --git a/Examples/test-suite/errors/cpp_template_duplicate.i b/Examples/test-suite/errors/cpp_template_duplicate.i new file mode 100644 index 000000000..672c9884f --- /dev/null +++ b/Examples/test-suite/errors/cpp_template_duplicate.i @@ -0,0 +1,20 @@ +%module xxx + +%include + +// 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; +%template(std_vector_boolean_type_duplicate) std::vector; +%template(std_vector_uint8_type) std::vector; + +namespace std { +%template(std_vector_boolean_type_again) vector; +%template(std_vector_uint8_type_again) vector; +%template(std_vector_unsigned_char) vector; +} diff --git a/Examples/test-suite/errors/cpp_template_duplicate.stderr b/Examples/test-suite/errors/cpp_template_duplicate.stderr new file mode 100644 index 000000000..b23e64dbb --- /dev/null +++ b/Examples/test-suite/errors/cpp_template_duplicate.stderr @@ -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'. diff --git a/Examples/test-suite/template_duplicate.i b/Examples/test-suite/template_duplicate.i new file mode 100644 index 000000000..a9860f01f --- /dev/null +++ b/Examples/test-suite/template_duplicate.i @@ -0,0 +1,21 @@ +%module template_duplicate + +%include + +%warnfilter(SWIGWARN_TYPE_REDEFINED) std::vector; +%warnfilter(SWIGWARN_TYPE_REDEFINED) std::vector; + +%inline %{ +typedef unsigned char uint8_T; +typedef unsigned char boolean_T; +%} + +%template(std_vector_boolean_type) std::vector; +%template(std_vector_boolean_type_duplicate) std::vector; +%template(std_vector_uint8_type) std::vector; + +namespace std { +%template(std_vector_boolean_type_again) vector; +%template(std_vector_uint8_type_again) vector; +%template(std_vector_unsigned_char) vector; +} diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index c28226044..aa35c4ec7 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -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 {