This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/38005] inconsistent precedence of operators in namespaces
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Nov 2008 10:31:18 -0000
- Subject: [Bug c++/38005] inconsistent precedence of operators in namespaces
- References: <bug-38005-16902@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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