'only defines private ctor' warning - 2b smarter
Yotam Medini
yotam@avanticorp.com
Fri Aug 14 11:30:00 GMT 1998
g++ 2.8.1 and also egcs's 19980525 snapshot
give a warning that a class
'only defines private constructors and has no friend'
ignoring the not-so-rare possibility that it may be constructed
thru a public static method.
I think if a class has a public static method such a warning
should be suppressed.
Being even smarter, and further check if static member
returns a class pointer?
...hmmm.. I don't think it will help since it does not cover
all legitimate constructions cases.
-- yotam
------------------------------------------------------------------------
telaviv:6034> cat sc.cc
// class created thru static member only
class C {
public:
static C* s_create(int id);
private:
C(int id): _id(id) {} // via create
C(); // not available
C(const C&); // not available
int _id;
}; // C
C* C::s_create(int id)
{
return(new C(id));
}
telaviv:6035> /site/seg/gcc-2.8.1/bin/g++ -v
Reading specs from /site/seg/gcc-2.8.1/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.1/specs
gcc version 2.8.1
telaviv:6036> /site/seg/gcc-2.8.1/bin/g++ -c -Wall sc.cc
sc.cc:10: warning: `class C' only defines private constructors and has no friends
telaviv:6037> ~seg/yotam/build/egcs/Solaris/bin/g++ -v
Reading specs from /home/seg/yotam/build/egcs/Solaris/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.91.33/specs
gcc version egcs-2.91.33 19980525 (gcc2 ss-980502 experimental)
telaviv:6038> ~seg/yotam/build/egcs/Solaris/bin/g++ -c -Wall sc.cc
sc.cc:10: warning: `class C' only defines private constructors and has no friends
telaviv:6039>
More information about the Gcc-bugs
mailing list