This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Incorrect unused statement warnings
- To: egcs-bugs at cygnus dot com
- Subject: Incorrect unused statement warnings
- From: David Mazieres <dm at reeducation-labor dot lcs dot mit dot edu>
- Date: Fri, 19 Jun 1998 03:11:29 -0400 (EDT)
I'm using:
Reading specs from /usr/local/egcs/lib/gcc-lib/i386-netbsd/egcs-2.91.40/specs
gcc version egcs-2.91.40 19980614 (gcc2 ss-980502 experimental)
EGCS generates incorrect "statement with no effect" warnings when
initializing variables from default constructors. The easiest way to
see this is to compile a simple program using STL. The following
program:
#include <hash_map>
hash_map<int, char *> hm;
Results in these warnings.
% c++ -c -O2 -Wall h.C
/usr/local/egcs/include/g++/stl_hashtable.h: In method `hashtable<pair<const int,char *>,int,hash<int>,select1st<pair<const int,char *> >,equal_to<int>,__default_alloc_template<false,0> >::hashtable<pair<const int,char *>, int, hash<int>, select1st<pair<const int,char *> >, equal_to<int>, alloc>(unsigned int, const struct hash<int> &, const struct equal_to<int> &)':
/usr/local/egcs/include/g++/stl_hash_map.h:78: instantiated from `hash_map<int,char *,hash<int>,equal_to<int>,__default_alloc_template<false,0> >::hash_map<int, char *, hash<int>, equal_to<int>, alloc>()'
h.C:3: instantiated from here
/usr/local/egcs/include/g++/stl_hashtable.h:220: warning: statement with no effect
These warnings are incorrect, because in general there is no way to
get rid of such statements. The following simpler, self-contained
example illustrates the problem:
struct bar {
int operator() (int);
};
template<class F>
class c1 {
c1 ();
F f;
public:
c1 (const F &ff) : f (ff) {};
};
template<class T>
class c2 : public c1<T> {
public:
c2 () : c1 (T ()) {}
};
c2<bar> xxx;
This legitimate program cannot be made to compile without warnings.
EGCS reports:
h.C: In method `c1<bar>::c1<bar>(const struct bar &)':
h.C:16: instantiated from `c2<bar>::c2<bar>()'
h.C:19: instantiated from here
h.C:10: warning: statement with no effect
But how else can one feed a default T to c1's constructor?
Thanks,
David