g++ parser bug?

James Lewis Nance jlnance@worldnet.att.net
Thu Mar 23 14:18:00 GMT 2000


Hello All,
    I think I may have found a bug in the g++ parser.  I dont know C++ well
enough to know if this should compile, but it does compile and run on 2
other c++ compilers (MRI & Digital Unix).  It fails on gcc-2.95.2,
gcc-2.8.something, and Mike Shaver reported that it failed on the most
recent gcc snapshot.  My coworker, Bill Gutknecht, came up with this
minimal testcase to demonstrate the problem.

Thanks,

Jim

extern "C" int printf(const char*, ...);

class a {

   friend class c;

public:

   a() : data(10) 
      { printf("constructor a\n"); };

private:

   int data;

};

class c {

public:

   c(const a & arg)
      { printf("constructor c arg.data = %d \n",arg.data); };
   c(const a & arg, int arg2) 
      { printf("constructor c arg.data = %d arg2 = %d\n",arg.data,arg2); };

};

main()
{

   c foo1(a()); // Compiles & runs, but does not do anything
   c foo2((class a) a()); // Compiles, and runs properly
   c foo3(a(),1); // Does not compile (must be barfing on the "1")
   c foo4((class a) a(),1); // Compiles and runs properly

}



More information about the Gcc-bugs mailing list