This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Longstanding g++ parser bug?
- To: bagnara at cs dot unipr dot it
- Subject: Re: Longstanding g++ parser bug?
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Sun, 5 Mar 2000 13:30:44 +0100
- CC: gcc-bugs at gcc dot gnu dot org
- References: <38C24B22.AF5D117E@cs.unipr.it>
> the present snippet may show a bug in g++ or may simply
> show that I am still far from mastering C++.
Thanks for your bug report. I think both is the case, please have a
look at
http://gcc.gnu.org/bugs.html#parsing
> void bar() {
> // g++ does not complain here: I believe he is right.
> foo p(a());
> foo q(5, a());
> foo r(a(), a());
g++ is right accepting it, but it may not express what you want. p and
r are functions: p is a function expecting a function with no
arguments, returning a, returning foo. Same for r().
The problem is that a line like that, which could be considered a
variable declaration or a function declaration, is a function
declaration.
> // g++ does complain here: I believe he is wrong.
> foo s(a(), 5);
> }
The work-around in all these cases is to make it clear that you really
mean an expression, eg
a mya;
foo p(mya);
foo q(5, mya);
foo r(mya, mya);
foo s(mya, 5);
Of course, this has a slightly different meaning from your original
code. If you really want to pass newly-constructed objects, you can
write (e.g. in the fourth case)
foo s((0,a()), 5);
Regards,
Martin