strange thing with template evaluation
Mon May 31 21:06:00 GMT 1999
On May 11, 1999, "Martin v. Loewis" <email@example.com> wrote:
>> 18 C1<C2> c1(C2());
> The problem is that the compiler takes this as a function declaration,
> named c1, expecting a function taking no arguments, returning C2, and
> returning C1<C2>.
> I get always confused how C++ does this ambiguity resolution, but I
> think g++ is wrong, and I think this is known problem and inherently
> hard to fix.
Nope. In this case, g++ is right. The general rule is: if some
sequence of tokens can be parsed as a declaration (as opposed to a
statement), it must be. If some sequence of tokens can be parsed as a
type name (as opposed to an expression), it must be. Since `C2()',
is a type name, it is parsed as an unnamed parameter, and c1 is the
declaration of a function.
A simple trick to resolve the ambiguity in favor of an expression is
to add extra parentheses around the whole expression: `c1((C2()))'
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
*** E-mail about software projects will be forwarded to mailing lists
More information about the Gcc-bugs