1.1b: -pedantic results in "parse error"
Louidor Erez
s3824888@techst02.technion.ac.il
Fri Oct 2 14:21:00 GMT 1998
On 1 Oct 1998, Alexandre Oliva wrote:
> J H M Dassen <jdassen@wi.leidenuniv.nl> writes:
>
> > [This problem has been reported as a bug through the Debian bugtracking
> > system ( http://www.debian.org/Bugs/ ); please Cc: 27217@bugs.debian.org on
> > on-topic replies]
>
> > include <vector>
> > template<class T> void foo() { std::vector<T>::iterator i; }
>
> > /scratch/test$ g++ -Wall -c test.cc
> > /scratch/test$ g++ -Wall -pedantic -c test.cc
> > test.cc: In function `void foo()':
> > test.cc:2: parse error before `;'
>
> This is not a bug. The C++ Standard requires that any
> template-dependent type name must be preceded by the `typename'
> keyword. Although egcs will try to parse template-dependent type
> names as types even when the mandated `typename' keyword is missing,
> this extension won't be considered when `-pedantic' mode is enabled,
> because this switch is documented as asking egcs to avoid accepting
> any non-standard constructs.
>
> --
> Alexandre Oliva
> mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
> http://www.dcc.unicamp.br/~oliva
> Universidade Estadual de Campinas, SP, Brasil
>
I believe it is a bug, because the compiler can look at the definition
of vector and find the iterator typedef and deduce it to be a type.
(It turns out that Stroustrup has this exact example on page 856-858
in his 'The C++ Programmin Language / Third Edition').
What is interesting is that the compiler does behave correctly (doesn't
say anything) for one-parameter templates. For instance the following
code gets an incorrect compilation error:
template<class T, class alloc = int>
class Vector {
public:
typedef T* iterator;
};
template<class T>
void f()
{
Vector<T, int>::iterator i = 0;
}
when compiled using: eg++ -Wall -pedantic -c typename1.cc
however when I removed the second template parameter (the class alloc)
it compiled using the same command line without an error.
'eg++ -v' reported:
Reading specs from
/usr/local/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release).
Hope this helps,
Erez.
More information about the Gcc-bugs
mailing list