[new testcase] Re: 1.1b: -pedantic results in "parse error"

Alexandre Oliva oliva@dcc.unicamp.br
Fri Oct 2 21:22:00 GMT 1998


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: typename1.C
Type: text/x-c++
Size: 336 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/19981002/368c25e9/attachment.bin>


More information about the Gcc-bugs mailing list