This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: typedef, class template and inheritance
- To: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Subject: Re: typedef, class template and inheritance
- From: Gabriel Dos Reis <Gabriel dot Dos-Reis at dptmaths dot ens-cachan dot fr>
- Date: Sat, 4 Oct 1997 13:09:59 +0200 (MET DST)
- Cc: Gabriel Dos Reis <Gabriel dot Dos-Reis at dptmaths dot ens-cachan dot fr>, egcs-bugs at cygnus dot com
- References: <199710030106.DAA07262@basson.dptmaths.ens-cachan.fr><oren62sosy.fsf@sunsite.dcc.unicamp.br>
>>>>> ĞAlexandreğ, Alexandre Oliva <oliva@dcc.unicamp.br> wrote:
Alexandre> Gabriel Dos Reis writes:
>> % g++ -c toto.C
>> toto.C:13: new declaration `T bar<T>::foobar()'
>> toto.C:10: ambiguates old declaration `typename foo<T,T>::fred_t bar<T>::foobar()'
>> gcc shouldn't flag the former code not legal. Should it ?
Alexandre> Yup. In fact, the declaration of foobar inside the body of bar<T>
Alexandre> should not be accepted. foo<T,T>::fred_t is not visible at that
Alexandre> point, since foo<T,T> might be specialized so that it does not declare
Alexandre> a fred_t type for some type T.
Alexandre> Instead of declaring the typedef as you did, you might have written:
Alexandre> template <class T> struct bar : public foo<T, T> {
Alexandre> typename foo<T,T>::fred_t foobar();
Alexandre> };
Alexandre> template <class T> typename foo<T,T>::fred_t bar<T>::foobar() {
Alexandre> return fred_t();
Alexandre> }
From my reading of Bjarne's 3rd edition "The C++ Progamming
Language", I understand that the keyword typename is required when the
type is a _parameter_ (the compiler is not psychic to figure out
whether fred_t is a type name or not). Here foo<T, T> is a class which
is actually defined: and gcc can look up the definition of class
foo<T, T>. For a specialization of class foo<T, T> where fred_t is not
defined, the behavior of gcc should not accept an _effective_ call of
foobar().
Consider the definitions of classes iterator and
reverse_iterator in Bjarne's book (chp 19). The behavior you described leads to
consider them not legal.
Best,
-- Gaby