This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

egcs bug report


[124] ~/src/atcserver >g++ -v
Reading specs from
/usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.21/specs
gcc version egcs-2.90.21 971202 (egcs-1.00 release)


[129] /tmp >uname -a
Linux singha.iii.ca 2.0.32 #3 Sat Dec 13 16:49:52 PST 1997 i586

../src/egcs-1.0/configure --host=i586-pc-linux-gnulibc1 --norecursion 


Problem description:
--------------------

The compiler generates a warning under the following conditions. I
define a
class with no public constructors and no friends but I define a static
function which is public which in turn calls the private constructor if
necessary.  This works as long as I don't define a  "dummy" constructor
and
"dummy" copy constructor (which prevents someone from using the
defaults). When I define these, the compiler outputs a warning, 
"warning: `class Test' only defines private constructors and has no
friends" 


Examples:
---------


// 
// Problem file
// g++    -c t2.cc -o t2.o
// t2.cc:14: warning: `class Test' only defines private constructors and
has no friends

#include <stdio.h>

class Test
{
   public:
      static Test& instance();

   private:
      Test();
      Test(const Test& other);
      Test& operator=(const Test& other);

      static Test* test;
};

Test* Test::test=NULL;

Test&
Test::instance()
{
   if (test == NULL) 
   {
      test = new Test;
   }

   return *test;
}



// This one is ok
// g++    -c t2.cc -o t2.o
// no errors or warnings
#include <stdio.h>

class Test
{
   public:
      static Test& instance();

   private:
      Test();
      static Test* test;
};

Test* Test::test=NULL;

Test&
Test::instance()
{
   if (test == NULL) 
   {
      test = new Test;
   }

   return *test;
}


-- 
Jason Fischl			Tel:   (604) 737-8547
Consultant			Fax:   (604) 737-8776
Image Integration Inc.		Email: j.fischl@ieee.org
------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]