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]

Re: Longstanding g++ parser bug?


> 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

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