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]
Other format: [Raw text]

[Bug c++/38005] inconsistent precedence of operators in namespaces



------- Comment #4 from rguenth at gcc dot gnu dot org  2008-11-04 10:31 -------
namespace A {
    class Parent{};
    ostream& operator<<(ostream&o,const Parent&){return o<<"parent\n";}
}

namespace B {
    class Child:public A::Parent{};
}

ostream& operator<<(ostream&o,const B::Child&){return o<<"child\n";}

namespace A{
    void foo(){
        B::Child child;
        cout<<child; //prints "parent"
    }
}

unqualified lookup of operator<< starts in namespace A and stops there.
argument dependent namelookup finds the same.  So GCCs behavior is correct.


namespace C{
    class Thing{};
    void operator<<(Thing&o,Thing&){} //completely unrelated operator<<

    void foo(){
        cout<<child;  //prints "parent"
    }
}

likewise.  You seem to miss that namelookup stops at the first match.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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