* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
@ 2008-11-03 17:48 ` c dot hite at rtsgroup dot net
2008-11-03 17:49 ` c dot hite at rtsgroup dot net
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: c dot hite at rtsgroup dot net @ 2008-11-03 17:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from c dot hite at rtsgroup dot net 2008-11-03 17:47 -------
Created an attachment (id=16620)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16620&action=view)
1
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38005
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
2008-11-03 17:48 ` [Bug c++/38005] " c dot hite at rtsgroup dot net
@ 2008-11-03 17:49 ` c dot hite at rtsgroup dot net
2008-11-03 17:53 ` c dot hite at rtsgroup dot net
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: c dot hite at rtsgroup dot net @ 2008-11-03 17:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from c dot hite at rtsgroup dot net 2008-11-03 17:47 -------
Created an attachment (id=16621)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16621&action=view)
2
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38005
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
2008-11-03 17:48 ` [Bug c++/38005] " c dot hite at rtsgroup dot net
2008-11-03 17:49 ` c dot hite at rtsgroup dot net
@ 2008-11-03 17:53 ` c dot hite at rtsgroup dot net
2008-11-04 10:32 ` rguenth at gcc dot gnu dot org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: c dot hite at rtsgroup dot net @ 2008-11-03 17:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from c dot hite at rtsgroup dot net 2008-11-03 17:51 -------
The way in which the compiler finds operators has something is referred to as
"Koenig Lookup".
--
c dot hite at rtsgroup dot net changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38005
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
` (2 preceding siblings ...)
2008-11-03 17:53 ` c dot hite at rtsgroup dot net
@ 2008-11-04 10:32 ` rguenth at gcc dot gnu dot org
2008-11-04 10:49 ` c dot hite at rtsgroup dot net
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-11-04 10:32 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
` (3 preceding siblings ...)
2008-11-04 10:32 ` rguenth at gcc dot gnu dot org
@ 2008-11-04 10:49 ` c dot hite at rtsgroup dot net
2008-11-04 12:52 ` rguenth at gcc dot gnu dot org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: c dot hite at rtsgroup dot net @ 2008-11-04 10:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from c dot hite at rtsgroup dot net 2008-11-04 10:47 -------
I'm fine with case #1. I don't know if Sun is wrong, or there is no "right".
#2 is a BUG.
No, the lookup doesn't stop at "operator<<(Thing&o,Thing&)", it keeps going,
but it keeps going differently.
Please look at it. In namespace C after the compiler realizes that the local
operator doesn't match, I expect it to try the other operators in the same
order as if that local operator didn't exist.
Why do C and D generate different calls? When deciding between the other two
operators outside their namespace C and D should reach the same decision.
--
c dot hite at rtsgroup dot net changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38005
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
` (4 preceding siblings ...)
2008-11-04 10:49 ` c dot hite at rtsgroup dot net
@ 2008-11-04 12:52 ` rguenth at gcc dot gnu dot org
2008-11-04 13:38 ` c dot hite at rtsgroup dot net
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-11-04 12:52 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from rguenth at gcc dot gnu dot org 2008-11-04 12:51 -------
You are wrong. Name-lookup _does_ stop at the first match. Name-lookup has
nothing to do with declaration matching - it only looks up names.
--
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
` (5 preceding siblings ...)
2008-11-04 12:52 ` rguenth at gcc dot gnu dot org
@ 2008-11-04 13:38 ` c dot hite at rtsgroup dot net
2008-11-04 14:23 ` schwab at suse dot de
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: c dot hite at rtsgroup dot net @ 2008-11-04 13:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from c dot hite at rtsgroup dot net 2008-11-04 13:36 -------
If it stopped at the first match, then the call in C would match the operator
in C and say the operands don't match and not compile. Instead C goes on to
call an operator defined in A.
Why does C check A and not the global space first?
Why does D do it the other way around?
Note that if we were talking about functions there is no way C or D could call
anything in A without a using clause or explicit "A::". Operators do a Koenig
lookup, which is a bit different. I think there's something buggy about it.
--
c dot hite at rtsgroup dot net changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38005
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
` (6 preceding siblings ...)
2008-11-04 13:38 ` c dot hite at rtsgroup dot net
@ 2008-11-04 14:23 ` schwab at suse dot de
2008-11-04 15:16 ` rguenth at gcc dot gnu dot org
2008-11-04 17:11 ` c dot hite at rtsgroup dot net
9 siblings, 0 replies; 11+ messages in thread
From: schwab at suse dot de @ 2008-11-04 14:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from schwab at suse dot de 2008-11-04 14:21 -------
::operator<< is hidden by C::operator<< and cannot be found by name lookup.
A::operator<< is found because child is-a A::parent.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38005
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
` (7 preceding siblings ...)
2008-11-04 14:23 ` schwab at suse dot de
@ 2008-11-04 15:16 ` rguenth at gcc dot gnu dot org
2008-11-04 17:11 ` c dot hite at rtsgroup dot net
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-11-04 15:16 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from rguenth at gcc dot gnu dot org 2008-11-04 15:15 -------
there are two name-lookup stages for unqualified ids, first regular unqualified
lookup which finds the local operator<< then argument-dependent lookup (Koenig
lookup) which finds operator<< in A.
--
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/38005] inconsistent precedence of operators in namespaces
2008-11-03 17:45 [Bug c++/38005] New: inconsistent precedence of operators in namespaces c dot hite at rtsgroup dot net
` (8 preceding siblings ...)
2008-11-04 15:16 ` rguenth at gcc dot gnu dot org
@ 2008-11-04 17:11 ` c dot hite at rtsgroup dot net
9 siblings, 0 replies; 11+ messages in thread
From: c dot hite at rtsgroup dot net @ 2008-11-04 17:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from c dot hite at rtsgroup dot net 2008-11-04 17:10 -------
So you're saying this isn't a bug because G++ does what it does?
Is there no standard specifying what should happen? I would like to think if
two different compilers produce different results, one of them has a bug.
Would you say Sun has a bug?
As far as I'm concerned, it's best to define the operator in the same namespace
as its operands.
I'm willing to give up. Thanks for your time.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38005
^ permalink raw reply [flat|nested] 11+ messages in thread