Redefinition/redeclaration warning message improvements

Add more information to these warning messages, including the
declaration for easier identification of the conflicting symbols.
Provides more consistent identifier names for constructors and methods.
Previously constructors did not display the template parameters, whereas
methods did. Incorrect 'renamed from' was also been shown for templated
methods (mmm in new testcase cpp_template_redefine.i).
This commit is contained in:
William S Fulton 2023-07-25 21:39:52 +01:00
parent 94ab699075
commit 856d6f25e9
9 changed files with 222 additions and 67 deletions

View File

@ -1,6 +1,6 @@
c_redefine.i:4: Warning 302: Identifier 'foo' redefined (ignored),
c_redefine.i:3: Warning 302: previous definition of 'foo'.
c_redefine.i:8: Warning 302: Identifier 'bar' redefined (ignored),
c_redefine.i:6: Warning 302: previous definition of 'bar'.
c_redefine.i:14: Warning 322: Redundant redeclaration of 'bar' (Renamed from 'spam'),
c_redefine.i:6: Warning 322: previous declaration of 'bar'.
c_redefine.i:4: Warning 302: Redefinition of identifier 'foo' (ignored) as foo,
c_redefine.i:3: Warning 302: previous definition of 'foo' as foo(int,int).
c_redefine.i:8: Warning 302: Redefinition of identifier 'bar' (ignored) as bar(),
c_redefine.i:6: Warning 302: previous definition of 'bar' as bar(int).
c_redefine.i:14: Warning 322: Redundant redeclaration of identifier 'bar' as spam(int) (Renamed from 'spam'),
c_redefine.i:6: Warning 322: previous declaration of 'bar' as bar(int).

View File

@ -1,5 +1,5 @@
cpp_class_definition.i:11: Warning 302: Identifier 'L' redefined (ignored),
cpp_class_definition.i:10: Warning 302: previous definition of 'L'.
cpp_class_definition.i:11: Warning 302: Redefinition of identifier 'L' (ignored) as Space11::SubSpace11::L(),
cpp_class_definition.i:10: Warning 302: previous definition of 'L' as Space11::SubSpace11::L().
cpp_class_definition.i:22: Error: 'Space1::A' resolves to 'Space1::A' and was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'.
cpp_class_definition.i:31: Error: Using the unary scope operator :: in class definition '::Space2::B' is invalid.
cpp_class_definition.i:38: Error: Using the unary scope operator :: in class definition '::XX' is invalid.

View File

@ -1,11 +1,11 @@
cpp_extend_destructors.i:8: Warning 302: Identifier '~AStruct' redefined by %extend (ignored),
cpp_extend_destructors.i:5: Warning 302: %extend definition of '~AStruct'.
cpp_extend_destructors.i:14: Warning 302: Identifier '~BStruct' redefined (ignored),
cpp_extend_destructors.i:13: Warning 302: previous definition of '~BStruct'.
cpp_extend_destructors.i:87: Warning 302: Identifier '~JStruct' redefined (ignored),
cpp_extend_destructors.i:85: Warning 302: previous definition of '~JStruct'.
cpp_extend_destructors.i:100: Warning 302: Identifier '~LStruct' redefined (ignored),
cpp_extend_destructors.i:98: Warning 302: previous definition of '~LStruct'.
cpp_extend_destructors.i:14: Warning 302: Redefinition of identifier '~BStruct' (ignored) as BStruct::~BStruct(),
cpp_extend_destructors.i:13: Warning 302: previous definition of '~BStruct' as BStruct::~BStruct().
cpp_extend_destructors.i:87: Warning 302: Redefinition of identifier '~JStruct' (ignored) as JStruct::~JStruct(),
cpp_extend_destructors.i:85: Warning 302: previous definition of '~JStruct' as JStruct::~JStruct().
cpp_extend_destructors.i:100: Warning 302: Redefinition of identifier '~LStruct' (ignored) as LStruct::~LStruct(),
cpp_extend_destructors.i:98: Warning 302: previous definition of '~LStruct' as LStruct::~LStruct().
cpp_extend_destructors.i:24: Warning 521: Illegal destructor name CStruct::~NOT_CStruct(). Ignored.
cpp_extend_destructors.i:30: Warning 521: Illegal destructor name DStruct::~NOT_DStruct(). Ignored.
cpp_extend_destructors.i:44: Warning 521: Illegal destructor name EStruct::~NOT_EStruct(). Ignored.

View File

@ -1,4 +1,4 @@
cpp_extend_redefine.i:9: Warning 302: Identifier 'bar' redefined by %extend (ignored),
cpp_extend_redefine.i:5: Warning 302: %extend definition of 'bar'.
cpp_extend_redefine.i:14: Warning 322: Redundant redeclaration of 'spam',
cpp_extend_redefine.i:10: Warning 322: previous declaration of 'spam'.
cpp_extend_redefine.i:14: Warning 322: Redundant redeclaration of identifier 'spam' as foo::spam(),
cpp_extend_redefine.i:10: Warning 322: previous declaration of 'spam' as foo::spam().

View File

@ -1,14 +1,14 @@
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:14: Warning 302: Identifier 'Duplicate1' redefined (ignored),
cpp_template_duplicate_names.i:13: Warning 302: previous definition of 'Duplicate1'.
cpp_template_duplicate_names.i:14: Warning 302: Redefinition of identifier 'Duplicate1' (ignored) as Space::Duplicate1(),
cpp_template_duplicate_names.i:13: Warning 302: previous definition of 'Duplicate1' as Space::Duplicate1().
cpp_template_duplicate_names.i:14: Warning 302: Redefinition of identifier 'Duplicate1' (ignored) as Space::Duplicate1(),
cpp_template_duplicate_names.i:13: Warning 302: previous definition of 'Duplicate1' as Space::Duplicate1().
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:47: Warning 302: Redefinition of identifier 'Duplicate4' (ignored) as Space::Duplicate4(),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4' as Space::Duplicate4().
cpp_template_duplicate_names.i:47: Warning 302: Redefinition of identifier 'Duplicate4' (ignored) as Space::Duplicate4(),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4' as Space::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

@ -1,8 +1,8 @@
cpp_template_friend.i:4: Warning 302: Identifier 'template_friend1' redefined (ignored),
cpp_template_friend.i:3: Warning 302: previous definition of 'template_friend1'.
cpp_template_friend.i:13: Warning 302: Identifier 'template_friend2' redefined (ignored),
cpp_template_friend.i:9: Warning 302: previous definition of 'template_friend2'.
cpp_template_friend.i:17: Warning 322: Redundant redeclaration of 'normal_friend1',
cpp_template_friend.i:16: Warning 322: previous declaration of 'normal_friend1'.
cpp_template_friend.i:26: Warning 322: Redundant redeclaration of 'normal_friend2',
cpp_template_friend.i:22: Warning 322: previous declaration of 'normal_friend2'.
cpp_template_friend.i:4: Warning 302: Redefinition of identifier 'template_friend1' (ignored) as template_friend1(T),
cpp_template_friend.i:3: Warning 302: previous definition of 'template_friend1' as template_friend1(T).
cpp_template_friend.i:13: Warning 302: Redefinition of identifier 'template_friend2' (ignored) as template_friend2(T),
cpp_template_friend.i:9: Warning 302: previous definition of 'template_friend2' as template_friend2(T).
cpp_template_friend.i:17: Warning 322: Redundant redeclaration of identifier 'normal_friend1' as normal_friend1(int),
cpp_template_friend.i:16: Warning 322: previous declaration of 'normal_friend1' as normal_friend1(int).
cpp_template_friend.i:26: Warning 322: Redundant redeclaration of identifier 'normal_friend2' as normal_friend2(int),
cpp_template_friend.i:22: Warning 322: previous declaration of 'normal_friend2' as normal_friend2(int).

View File

@ -0,0 +1,107 @@
%module xxx
// This is a copy of Examples/test-suite/cpp11_template_parameters_decltype
%inline %{
// Github issue #1589
template <decltype(true) X = true>
void A() { }
%}
// %template(A) A<>; // not working
%template(A) A<true>; // workaround
%include <std_string.i>
%include <std_vector.i>
%include <std_map.i>
//#pragma SWIG nowarn=SWIGWARN_CPP11_DECLTYPE
%{
// Simple implementation of helper functions required in test below
std::string array(std::vector<std::string>::const_iterator begin, std::vector<std::string>::const_iterator end) {
return "not implemented";
}
std::string object(std::map<std::string, std::string>::const_iterator begin, std::map<std::string, std::string>::const_iterator end) {
return "not implemented";
}
%}
%inline %{
#include <iostream>
// Github issue #1590
struct Converter {
std::string to_json() const { return std::string(); }
};
struct Json {
int ctor;
Json(std::string s) : ctor(0) {}
template < class T, class = decltype(&T::to_json) >
Json(const T & t) : Json(t.to_json()) { ctor = 1; }
// Github issue #1589
// Implicit constructor: map-like objects (std::map, std::unordered_map, etc)
template <class M, typename std::enable_if<
std::is_constructible<std::string, decltype(std::declval<M>().begin()->first)>::value,
int>::type = 0>
Json(const M & m) : Json(object(m.begin(), m.end())) { ctor = 2; }
// Implicit constructor: vector-like objects (std::list, std::vector, std::set, etc)
template <class V, typename std::enable_if<
std::is_constructible<Json, decltype(*std::declval<V>().begin())>::value,
int>::type = 0>
Json(const V & v) : Json(array(v.begin(), v.end())) { ctor = 3; }
// Same sort of thing as constructors above but for a member function
int mmm(std::string s) { return 100; }
template < class T, class = decltype(&T::to_json) >
int mmm(const T & t) { return 101; }
template <class M, typename std::enable_if<
std::is_constructible<std::string, decltype(std::declval<M>().begin()->first)>::value,
int>::type = 0>
int mmm(const M & m) { return 102; }
template <class V, typename std::enable_if<
std::is_constructible<Json, decltype(*std::declval<V>().begin())>::value,
int>::type = 0>
int mmm(const V & v) { return 103; }
};
void tester(bool show) {
// Example usage from c++
if (show) {
Json json0(std::string("hi"));
Converter converter;
std::cout << "json0 " << json0.ctor << std::endl;
Json json1 = Json(converter);
std::cout << "json1 " << json1.ctor << std::endl;
std::map<std::string, std::string> myStringStringMap;
Json json2 = Json(myStringStringMap);
std::cout << "json2 " << json2.ctor << std::endl;
std::vector<std::string> myVectorString;
Json json3 = Json(myVectorString);
std::cout << "json3 " << json3.ctor << std::endl;
std::cout << "json0.mmm " << json0.mmm("bye") << std::endl;
std::cout << "json1.mmm " << json1.mmm(converter) << std::endl;
std::cout << "json2.mmm " << json2.mmm(myStringStringMap) << std::endl;
std::cout << "json3.mmm " << json3.mmm(myVectorString) << std::endl;
}
}
%}
%template(VectorString) std::vector<std::string>;
%template(MapStringString) std::map<std::string, std::string>;
// There is quite a bit of inconsistency about providing or not providing default
// template parameters that needs investigating. Below is a combination that works.
// Note that instantiating the two Json constructors (or the two mmm methods) that
// use enable_if is ambiguous given the enable_if is not evaluated by SWIG.
// %template(Json) Json::Json<Converter>; // not working
%template(Json) Json::Json<Converter, std::string>; // workaround
%template(Json) Json::Json<std::map<std::string, std::string>, 0>;
%template(Json) Json::Json<std::vector<std::string>, 0>;
%template(mmm) Json::mmm<Converter, std::string>;
%template(mmm) Json::mmm<std::map<std::string, std::string>, 0>;
%template(mmm) Json::mmm<std::vector<std::string>, 0>;

View File

@ -0,0 +1,30 @@
cpp_template_redefine.i:39: Warning 344: Unable to deduce decltype for '&T::to_json'.
cpp_template_redefine.i:45: Warning 344: Unable to deduce decltype for 'std::declval<M>().begin()->first'.
cpp_template_redefine.i:50: Warning 344: Unable to deduce decltype for '*std::declval<V>().begin()'.
cpp_template_redefine.i:56: Warning 344: Unable to deduce decltype for '&T::to_json'.
cpp_template_redefine.i:59: Warning 344: Unable to deduce decltype for 'std::declval<M>().begin()->first'.
cpp_template_redefine.i:63: Warning 344: Unable to deduce decltype for '*std::declval<V>().begin()'.
cpp_template_redefine.i:101: Warning 322: Redundant redeclaration of identifier 'Json' as Json::Json(Converter const &),
cpp_template_redefine.i:101: Warning 322: previous declaration of 'Json' as Json::Json(Converter const &).
cpp_template_redefine.i:101: Warning 322: Redundant redeclaration of identifier 'Json' as Json::Json(Converter const &),
cpp_template_redefine.i:101: Warning 322: previous declaration of 'Json' as Json::Json(Converter const &).
cpp_template_redefine.i:102: Warning 322: Redundant redeclaration of identifier 'Json' as Json::Json(std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > const &),
cpp_template_redefine.i:102: Warning 322: previous declaration of 'Json' as Json::Json(std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > const &).
cpp_template_redefine.i:102: Warning 322: Redundant redeclaration of identifier 'Json' as Json::Json(std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > const &),
cpp_template_redefine.i:102: Warning 322: previous declaration of 'Json' as Json::Json(std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > const &).
cpp_template_redefine.i:103: Warning 322: Redundant redeclaration of identifier 'Json' as Json::Json(std::vector< std::string,std::allocator< std::string > > const &),
cpp_template_redefine.i:103: Warning 322: previous declaration of 'Json' as Json::Json(std::vector< std::string,std::allocator< std::string > > const &).
cpp_template_redefine.i:103: Warning 322: Redundant redeclaration of identifier 'Json' as Json::Json(std::vector< std::string,std::allocator< std::string > > const &),
cpp_template_redefine.i:103: Warning 322: previous declaration of 'Json' as Json::Json(std::vector< std::string,std::allocator< std::string > > const &).
cpp_template_redefine.i:105: Warning 322: Redundant redeclaration of identifier 'mmm' as Json::mmm< Converter,std::string >(Converter const &),
cpp_template_redefine.i:105: Warning 322: previous declaration of 'mmm' as Json::mmm< Converter,std::string >(Converter const &).
cpp_template_redefine.i:105: Warning 322: Redundant redeclaration of identifier 'mmm' as Json::mmm< Converter,std::string >(Converter const &),
cpp_template_redefine.i:105: Warning 322: previous declaration of 'mmm' as Json::mmm< Converter,std::string >(Converter const &).
cpp_template_redefine.i:106: Warning 322: Redundant redeclaration of identifier 'mmm' as Json::mmm< std::map< std::string,std::string >,0 >(std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > const &),
cpp_template_redefine.i:106: Warning 322: previous declaration of 'mmm' as Json::mmm< std::map< std::string,std::string >,0 >(std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > const &).
cpp_template_redefine.i:106: Warning 322: Redundant redeclaration of identifier 'mmm' as Json::mmm< std::map< std::string,std::string >,0 >(std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > const &),
cpp_template_redefine.i:106: Warning 322: previous declaration of 'mmm' as Json::mmm< std::map< std::string,std::string >,0 >(std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > const &).
cpp_template_redefine.i:107: Warning 322: Redundant redeclaration of identifier 'mmm' as Json::mmm< std::vector< std::string >,0 >(std::vector< std::string,std::allocator< std::string > > const &),
cpp_template_redefine.i:107: Warning 322: previous declaration of 'mmm' as Json::mmm< std::vector< std::string >,0 >(std::vector< std::string,std::allocator< std::string > > const &).
cpp_template_redefine.i:107: Warning 322: Redundant redeclaration of identifier 'mmm' as Json::mmm< std::vector< std::string >,0 >(std::vector< std::string,std::allocator< std::string > > const &),
cpp_template_redefine.i:107: Warning 322: previous declaration of 'mmm' as Json::mmm< std::vector< std::string >,0 >(std::vector< std::string,std::allocator< std::string > > const &).

View File

@ -673,44 +673,62 @@ static void add_symbols(Node *n) {
c = Swig_symbol_add(symname,n);
if (c != n) {
/* symbol conflict attempting to add in the new symbol */
if (Getattr(n,"sym:weak")) {
Setattr(n,"sym:name",symname);
} else {
String *e = NewStringEmpty();
String *en = NewStringEmpty();
String *ec = NewStringEmpty();
int redefined = Swig_need_redefined_warn(n,c,inclass);
if (redefined) {
Printf(en,"Identifier '%s' redefined (ignored)",symname);
Printf(ec,"previous definition of '%s'",symname);
} else {
Printf(en,"Redundant redeclaration of '%s'",symname);
Printf(ec,"previous declaration of '%s'",symname);
}
if (Cmp(symname,Getattr(n,"name"))) {
Printf(en," (Renamed from '%s')", SwigType_namestr(Getattr(n,"name")));
}
Printf(en,",");
if (Cmp(symname,Getattr(c,"name"))) {
Printf(ec," (Renamed from '%s')", SwigType_namestr(Getattr(c,"name")));
}
Printf(ec,".");
/* symbol conflict attempting to add in the new symbol */
if (Getattr(n,"sym:weak")) {
Setattr(n,"sym:name",symname);
} else {
String *e = NewStringEmpty();
String *en = NewStringEmpty();
String *ec = NewStringEmpty();
String *symname_stripped = SwigType_templateprefix(symname);
String *n_name_stripped = SwigType_templateprefix(Getattr(n, "name"));
String *c_name_stripped = SwigType_templateprefix(Getattr(c, "name"));
int redefined = Swig_need_redefined_warn(n, c, inclass);
String *n_name_decl = 0;
String *c_name_decl = Swig_name_decl(c);
{
/* As symbol add failed, temporarily add in missing symbol table for Swig_name_decl */
Symtab *n_symtab = Getattr(n, "sym:symtab");
if (!n_symtab)
Setattr(n, "sym:symtab", Swig_symbol_current());
n_name_decl = Swig_name_decl(n);
if (!n_symtab)
Delattr(n, "sym:symtab");
}
if (redefined) {
Printf(en, "Redefinition of identifier '%s' (ignored) as %s", symname_stripped, n_name_decl);
Printf(ec, "previous definition of '%s' as %s", symname_stripped, c_name_decl);
} else {
Printf(en, "Redundant redeclaration of identifier '%s' as %s", symname_stripped, n_name_decl);
Printf(ec, "previous declaration of '%s' as %s", symname_stripped, c_name_decl);
}
if (!Equal(symname_stripped, n_name_stripped)) {
Printf(en, " (Renamed from '%s')", SwigType_namestr(n_name_stripped));
}
Printf(en, ",");
if (!Equal(symname_stripped, c_name_stripped)) {
Printf(ec, " (Renamed from '%s')", SwigType_namestr(c_name_stripped));
}
Printf(ec, ".");
SWIG_WARN_NODE_BEGIN(n);
if (redefined) {
Swig_warning(WARN_PARSE_REDEFINED,Getfile(n),Getline(n),"%s\n",en);
Swig_warning(WARN_PARSE_REDEFINED,Getfile(c),Getline(c),"%s\n",ec);
} else if (!is_friend(n) && !is_friend(c)) {
Swig_warning(WARN_PARSE_REDUNDANT,Getfile(n),Getline(n),"%s\n",en);
Swig_warning(WARN_PARSE_REDUNDANT,Getfile(c),Getline(c),"%s\n",ec);
}
if (redefined) {
Swig_warning(WARN_PARSE_REDEFINED, Getfile(n), Getline(n), "%s\n", en);
Swig_warning(WARN_PARSE_REDEFINED, Getfile(c), Getline(c), "%s\n", ec);
} else if (!is_friend(n) && !is_friend(c)) {
Swig_warning(WARN_PARSE_REDUNDANT, Getfile(n), Getline(n), "%s\n", en);
Swig_warning(WARN_PARSE_REDUNDANT, Getfile(c), Getline(c), "%s\n", ec);
}
SWIG_WARN_NODE_END(n);
Printf(e,"%s:%d:%s\n%s:%d:%s\n",Getfile(n),Getline(n),en,
Getfile(c),Getline(c),ec);
Setattr(n,"error",e);
Printf(e, "%s:%d:%s\n%s:%d:%s\n", Getfile(n), Getline(n), en, Getfile(c), Getline(c), ec);
Setattr(n, "error", e);
Delete(c_name_decl);
Delete(n_name_decl);
Delete(symname_stripped);
Delete(c_name_stripped);
Delete(n_name_stripped);
Delete(e);
Delete(en);
Delete(ec);
Delete(en);
Delete(ec);
}
}
}