Duplicate class template instantiations via %template changes

Named duplicate class template instantiations now issue a warning and are ignored.
Duplicate empty class template instantiations are quietly ignored.

The test cases are fixed for this new behaviour.

This commit is a pre-requisite for the near future so that the Python
builtin wrappers can correctly use the SwigType_namestr function without
generating duplicate symbol names.
This commit is contained in:
William S Fulton 2022-11-18 18:49:48 +00:00
commit 4729cf2b1f
16 changed files with 283 additions and 55 deletions

View file

@ -0,0 +1,34 @@
%module xxx
template<typename T> struct A {};
%template(Aint) A<int>;
%template(Aint2) A<int>; // Now ignored and issues a warning
template<typename T> struct B {};
%template() B<int>;
%template(Bint) B<int>; // OK
template<typename T> struct C {};
%template() C<int>;
%template() C<int>; // Quietly ignored now
%template(Cint) C<int>; // OK
template <typename T, typename U = short> struct D {};
%template(Dint) D<int>;
%template(Dintshort) D<int, short>;
template<typename T> struct E {};
%template(Eint) E<int>;
%template(Eint) E<int>; // Always has been ignored as a redefined identifier
template<typename T> struct F {};
%template(Fint) F<int>;
%template() F<int>; // Quietly ignored
%template() F<int>; // Quietly ignored
template<typename T> struct G {};
%template() G<int>;
%template() G<int>; // Quietly ignored
%template(Gint) G<int>;
%template() G<int>; // Quietly ignored

View file

@ -0,0 +1,6 @@
cpp_template_class_repeat.i:5: Warning 404: Duplicate template instantiation of 'A< int >' with name 'Aint2' ignored,
cpp_template_class_repeat.i:4: Warning 404: previous instantiation of 'A< int >' with name 'Aint'.
cpp_template_class_repeat.i:18: Warning 404: Duplicate template instantiation of 'D< int,short >' with name 'Dintshort' ignored,
cpp_template_class_repeat.i:17: Warning 404: previous instantiation of 'D< int >' with name 'Dint'.
cpp_template_class_repeat.i:22: Warning 404: Duplicate template instantiation of 'E< int >' with name 'Eint' ignored,
cpp_template_class_repeat.i:21: Warning 404: previous instantiation of 'E< int >' with name 'Eint'.

View file

@ -2,13 +2,13 @@ cpp_template_duplicate_names.i:14: Warning 302: Identifier 'Duplicate1' redefine
cpp_template_duplicate_names.i:13: Warning 302: previous definition of 'Duplicate1'.
cpp_template_duplicate_names.i:14: Warning 302: Identifier 'Duplicate1' redefined (ignored),
cpp_template_duplicate_names.i:13: Warning 302: previous definition of 'Duplicate1'.
cpp_template_duplicate_names.i:25: Warning 302: Identifier 'Duplicate2_0' redefined (ignored) (Renamed from 'Duplicate2< 0 >'),
cpp_template_duplicate_names.i:24: Warning 302: previous definition of 'Duplicate2_0' (Renamed from 'Duplicate2< 0 >').
cpp_template_duplicate_names.i:35: Warning 302: Identifier 'Duplicate3' redefined (ignored) (Renamed from 'Duplicate3< 0 >'),
cpp_template_duplicate_names.i:31: Warning 302: previous definition of 'Duplicate3'.
cpp_template_duplicate_names.i:25: Warning 404: Duplicate template instantiation of 'Duplicate2< 0 >' with name 'Duplicate2_0' ignored,
cpp_template_duplicate_names.i:24: Warning 404: previous instantiation of 'Duplicate2< 0 >' with name 'Duplicate2_0'.
cpp_template_duplicate_names.i:35: Warning 404: Duplicate template instantiation of 'Duplicate3< 0 >' with name 'Duplicate3' ignored,
cpp_template_duplicate_names.i:34: Warning 404: previous instantiation of 'Duplicate3< 0 >' with name 'Duplicate3'.
cpp_template_duplicate_names.i:47: Warning 302: Identifier 'Duplicate4' redefined (ignored),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4'.
cpp_template_duplicate_names.i:47: Warning 302: Identifier 'Duplicate4' redefined (ignored),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4'.
cpp_template_duplicate_names.i:50: Warning 302: Identifier 'Duplicate4' redefined (ignored) (Renamed from 'Duplicate4< 0 >'),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4'.
cpp_template_duplicate_names.i:50: Warning 404: Duplicate template instantiation of 'Duplicate4< 0 >' with name 'Duplicate4' ignored,
cpp_template_duplicate_names.i:49: Warning 404: previous instantiation of 'Duplicate4< 0 >' with name 'Duplicate4'.

View file

@ -4,4 +4,15 @@ template<class T> T blah(T x) { };
%template(iblah) blah<int>;
%template(iiblah) blah<int>;
// The second %template instantiation above should surely be ignored with a warning, but doesn't atm
// empty template instantiations for template functions warn (unlike for template classes)
%template() blah<double>;
%template() blah<double>;
%template() blah<double>;
%template(sblah) blah<short>;
%template(sblah) blah<short>;
%template() blah<const char *>;
%template() blah<const char *>;
%template(sblah) blah<const char *>;

View file

@ -0,0 +1,6 @@
cpp_template_repeat.i:6: Warning 404: Duplicate template instantiation of 'blah< int >' with name 'iiblah' ignored,
cpp_template_repeat.i:5: Warning 404: previous instantiation of 'blah< int >' with name 'iblah'.
cpp_template_repeat.i:14: Warning 404: Duplicate template instantiation of 'blah< short >' with name 'sblah' ignored,
cpp_template_repeat.i:13: Warning 404: previous instantiation of 'blah< short >' with name 'sblah'.
cpp_template_repeat.i:9: Warning 519: %template() contains no name. Template method ignored: blah< double >(double)
cpp_template_repeat.i:16: Warning 519: %template() contains no name. Template method ignored: blah< char const * >(char const *)