This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
gcc-2.95.1: -Weffc++ is a little too strict about initialization
- To: gcc@gcc.gnu.org
- Subject: gcc-2.95.1: -Weffc++ is a little too strict about initialization
- From: greyham@research.canon.com.au (Graham Stoney)
- Date: Mon, 30 Aug 1999 17:55:48 +1000 (EST)
Hi folks,
The -Weffc++ flag in gcc-2.95.1 warns about constructs which break the rules
in Scott Myer's book "Effective C++". This is very cool. Rule 12 is "Prefer
initialization to assignment in constructors", so gcc-2.95.1 warns about any
member which isn't initialized in the member initialization list. This seem a
little excessive for plain old structure members which have no constructor of
their own and therefore cannot be initialized in the initialization list. Here
is an example with a class containing a POSIX thread mutex, which is a plain
old C structure, initialised either by structure assignment or a function call:
#include <pthread.h>
class C
{
pthread_mutex_t mutex;
public:
C::C();
};
C::C()
{
pthread_mutex_init(&mutex, NULL);
}
gcc-2.95.1 gives:
% g++ -Weffc++ weff.cc
weff.cc: In method `C::C()':
weff.cc:12: warning: `C::mutex' should be initialized in the member initialization list
It would be nice if gcc didn't warn about plain structure members which are
initialized in a constructor, given that they can't be initialized in the
member initialization list.
If it weren't for this, I could turn on -Werr too...
Thanks,
Graham