This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[new testcase] Re: 1.1b: -pedantic results in "parse error"
- To: Louidor Erez <s3824888 at techst02 dot technion dot ac dot il>
- Subject: [new testcase] Re: 1.1b: -pedantic results in "parse error"
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 03 Oct 1998 00:33:31 -300
- Cc: egcs-bugs at cygnus dot com, egcs-patches at cygnus dot com, jason at cygnus dot com
- References: <Pine.GSO.3.95.981002213238.10387A-100000@techst02.technion.ac.il>
Louidor Erez <s3824888@techst02.technion.ac.il> writes:
> On 1 Oct 1998, Alexandre Oliva wrote:
>> J H M Dassen <jdassen@wi.leidenuniv.nl> writes:
>> > include <vector>
>> > template<class T> void foo() { std::vector<T>::iterator i; }
>>
>> This is not a bug. The C++ Standard requires that any
>> template-dependent type name must be preceded by the `typename'
>> keyword.
> I believe it is a bug
It is not. It's a requirement for compliance with the C++ Standard.
> the compiler can look at the definition
> of vector and find the iterator typedef and deduce it to be a type.
It cannot, because you may specialize the template class vector after
the definition of the template function, in a way that the
specialization does not have a nested type named iterator.
> (It turns out that Stroustrup has this exact example on page 856-858
> in his 'The C++ Programmin Language / Third Edition').
His example is not compliant with the standard. Have you checked the
web-pages with updates for this book? This problem might be covered
there. Unfortunately, I don't have the URL, but I know such a
web-page exists.
> 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.
This example is ill-formed according to the C++ Standard, and so is
the example without the second template argument. Jason, is the
attached test-case ok to install 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
typename1.C