public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47957] New: Type mismatch when a class derived a same name with template parameter
@ 2011-03-02 16:06 boostcpp at gmail dot com
  2011-03-02 16:13 ` [Bug c++/47957] [4.3/4.4/4.5/4.6 Regression] " rguenth at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: boostcpp at gmail dot com @ 2011-03-02 16:06 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: boostcpp@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.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-06-27 12:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-02 16:06 [Bug c++/47957] New: Type mismatch when a class derived a same name with template parameter boostcpp at gmail dot com
2011-03-02 16:13 ` [Bug c++/47957] [4.3/4.4/4.5/4.6 Regression] " rguenth at gcc dot gnu.org
2011-03-02 18:21 ` jakub at gcc dot gnu.org
2011-03-03 11:20 ` jakub at gcc dot gnu.org
2011-03-03 23:43 ` jason at gcc dot gnu.org
2011-03-04 16:01 ` dodji at gcc dot gnu.org
2011-03-07 16:26 ` dodji at gcc dot gnu.org
2011-03-08 15:38 ` dodji at gcc dot gnu.org
2011-03-08 15:41 ` [Bug c++/47957] [4.3/4.4/4.5 " jakub at gcc dot gnu.org
2011-03-08 21:14 ` dodji at gcc dot gnu.org
2011-03-08 22:20 ` dodji at gcc dot gnu.org
2011-03-08 22:30 ` [Bug c++/47957] [4.3 " dodji at gcc dot gnu.org
2011-06-27 12:15 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).