Questionable 1.1 C++ parsing

Alexandre Oliva oliva@dcc.unicamp.br
Wed Sep 16 17:46:00 GMT 1998


Phil Blecker <tmwg@inxservices.com> writes:

> I expected the lines constructing n and i to be parsed the same in the
> attached files

Your expectations are correct, in this case.  There's an ambiguity in
the C++ grammar, and egcs will sometimes incorrectly decide how to
solve the ambiguity.  For example, if N were the name of a type, the
following declaration:

> 	const int i(int(sqrt(N())));

would be equivalent to:

        const int i(int sqrt(N (*)()));

But the egcs bug is still worse, since i is declared as a function
that takes an empty argument list.  It seems that `int(sqrt(N()))' is
being interpreted as a top-level declaration of a variable named sqrt,
initialized with N.  This can be verified with -Wall: it says that
variable `sqrt' is unused.

A real bug, indeed :-(

Jason, may I install the attached test case in g++.other?

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
-------------- next part --------------
// Build don't link:
// Based on a test case by Phil Blecker <tmwg@inxservices.com>

int foo(int);
int bar() {
  int baz(int(foo(bar())));
  int foo = baz;
}


More information about the Gcc-bugs mailing list