This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: typedef, class template and inheritance


>>>>> Ğ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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]