public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* 'only defines private ctor' warning - 2b smarter
@ 1998-08-14 11:30 Yotam Medini
0 siblings, 0 replies; only message in thread
From: Yotam Medini @ 1998-08-14 11:30 UTC (permalink / raw)
To: egcs-bugs
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>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1998-08-14 11:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-08-14 11:30 'only defines private ctor' warning - 2b smarter Yotam Medini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).