This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
GCC-2.95 misparses certain trivial code
- To: gcc-bugs at gcc dot gnu dot org
- Subject: GCC-2.95 misparses certain trivial code
- From: "Richard B. Kreckel" <kreckel at zino dot physik dot uni-mainz dot de>
- Date: Fri, 13 Aug 1999 17:07:42 +0200 (CEST)
- Reply-To: Richard dot Kreckel at Uni-Mainz dot DE
The following piece of valid C++ code is a boil-down of several parse
errors that keep me busy here. GCC-2.95 and 2.95.1 do not compile it.
However, it used to compile with EGCS-1.1.2 and earlier, even with ancient
GCC-2.7.2.3. (It also compiles fine on SUN WorkShop and DEC CXX.)
-------snip-----------8<-----------------------snip-----------8<---------
#include <iostream>
class foo
{
public:
foo() : a(0), b(0) {}; // default ctor
foo(int av, int bv) : a(av), b(bv) {};
~foo() {};
int getval1() { return a; };
int getval2() { return b; };
void print(ostream & os) { os << "(" << a << "," << b << ")" << endl;
}
private:
int a;
int b;
};
class bar
{
public:
bar(foo F);
~bar() {};
void print(ostream & os) { os << x << endl; }
private:
int x;
};
bar::bar(foo F) // ctor from foo
{ x = F.getval1(); }
int main()
{
bar(foo(1,2)).print(cout);
}
-------snip-----------8<-----------------------snip-----------8<---------
The error message is:
gromit:~C/test/$ c++ fcnmatch.cpp -o fcnmatch
fcnmatch.cpp: In function `int main()':
fcnmatch.cpp:32: no matching function for call to `bar::bar (int, int)'
fcnmatch.cpp:26: candidates are: bar::bar(foo)
fcnmatch.cpp:23: bar::bar(const bar &)
fcnmatch.cpp:32: parse error before `.'
Note: Changing the code in main() to
{
foo tmpfoo(1,2);
bar(tmpfoo).print(cout);
}
makes the program compile and correctly echo '1'. Since the
original version really ought to be parsed I guess this is
boil-down accounts for quite some other bugs.
Regards
-rbk.
--
Richard Kreckel
<Richard.Kreckel@Uni-Mainz.DE>
<http://wwwthep.physik.uni-mainz.de/~kreckel/>