http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47957

           Summary: Type mismatch when a class derived a same name with
                    template parameter
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: boost...@gmail.com


This bug report is for gcc 4.6(built in 2011/02/26)
I tried other version(gcc 4.1). But it doesn't have this problem.

struct Base
{
    typedef int T ;
} ;

template < typename T >
struct Derived : Base
{
    T member ; // T is Base::T, its type is int.
    void f()
    {// for instantiation Derived< double >
        // type of T is double
        std::cout << "T= " << typeid(T).name() << std::endl ;
        T variable ;
        // type of variable is double
        std::cout << "variable= " << typeid(variable).name() << std::endl ;
        // type of member is int
        std::cout << "member= " << typeid(member).name() << std::endl; 
    }
};


int main()
{
    Derived< double > d ;
    d.f() ;
}

Derived's base class is non-dependent name, so in the class scope Derived, name
T is Base::T, not a template parameter name T.

So for instantiation Derived<double>, the name T in Derived class scope is
Base::T. it's type is int.

But in gcc 4.6,
Although the type of Derived::member is int,
the type of T become double in the member function body.

It looks like gcc 4.6 treat name T as a template parameter T in member function
body.

Reply via email to