public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/7049 Overloading "cout <<" in one namespace obscures similar functions in a different namespace
@ 2002-06-18 4:46 Philip Martin
0 siblings, 0 replies; 5+ messages in thread
From: Philip Martin @ 2002-06-18 4:46 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c++/7049; it has been noted by GNATS.
From: Philip Martin <philip@codematters.co.uk>
To: steev@paradigmds.com, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org
Cc:
Subject: Re: c++/7049 Overloading "cout <<" in one namespace obscures similar functions in a different namespace
Date: 18 Jun 2002 12:30:14 +0100
This is not a bug, that's how name lookup works.
The compiler will lookup operator<< in the anonymous namespace where
the statement "cout << x" occurs, the std:: namespace where ostream is
defined, and the ns:: namespace where class X is defined. Since the
compiler will find an operator<< by doing this it won't look anywhere
else. In particular operator<< in the global namespace will not be
considered.
Put operator<< for X where it belongs, in the ns:: namespace that
defines class X.
--
Philip
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: c++/7049: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
@ 2002-06-18 6:06 paolo
0 siblings, 0 replies; 5+ messages in thread
From: paolo @ 2002-06-18 6:06 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, paolo, steev
Synopsis: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Tue Jun 18 05:23:37 2002
Responsible-Changed-Why:
.
State-Changed-From-To: open->closed
State-Changed-By: paolo
State-Changed-When: Tue Jun 18 05:23:37 2002
State-Changed-Why:
Philip is right (also double checked with two other respected
compilers).
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7049
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: c++/7049: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
@ 2002-06-17 5:10 paolo
0 siblings, 0 replies; 5+ messages in thread
From: paolo @ 2002-06-17 5:10 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, steev
Synopsis: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
State-Changed-From-To: feedback->open
State-Changed-By: paolo
State-Changed-When: Mon Jun 17 05:07:47 2002
State-Changed-Why:
Attachments provided.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7049
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: c++/7049: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
@ 2002-06-17 2:16 paolo
0 siblings, 0 replies; 5+ messages in thread
From: paolo @ 2002-06-17 2:16 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, steev
Synopsis: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
State-Changed-From-To: open->feedback
State-Changed-By: paolo
State-Changed-When: Mon Jun 17 02:13:16 2002
State-Changed-Why:
Hi. For some reason, both 'bug2.cpp' and 'testout' got lost.
Could you possibly provide them again?
Thanks, Paolo.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7049
^ permalink raw reply [flat|nested] 5+ messages in thread
* c++/7049: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
@ 2002-06-17 2:13 steev
0 siblings, 0 replies; 5+ messages in thread
From: steev @ 2002-06-17 2:13 UTC (permalink / raw)
To: gcc-gnats
>Number: 7049
>Category: c++
>Synopsis: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jun 17 01:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Steev Wilcox
>Release: 3.1 (sparc-sun-solaris2.8)
>Organization:
>Environment:
Solaris 8
>Description:
If you define a operator<<(ostream&,thing) for an object X in one namespace, then in another namespace, define the same sort of function for a different object Y, it hides the original function so you can't print objects of type X in the namespace associated with object Y.
Fairly obvious workaround: don't define operator<<'s in namespaces - make sure they always go in the global namespace. Bjarne wouldn't be pleased, though. I'm not 100% certain this is a bug and not a "feature" of C++ - it just looks suspicious.
I haven't been able to find this in the list of known bugs, but it doesn't mean it's not there.
Thanks for your time, Steev
>How-To-Repeat:
Compile bug2.cpp with "g++ -c bug2.cpp". It'll fail in the way indicated in file "testout". If you place the definition of the operator<< on Y in the global namespace, g++ can suddenly find the definition of operator<< on X.
>Fix:
For workaround, see above.
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-06-18 12:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-18 4:46 c++/7049 Overloading "cout <<" in one namespace obscures similar functions in a different namespace Philip Martin
-- strict thread matches above, loose matches on Subject: below --
2002-06-18 6:06 c++/7049: " paolo
2002-06-17 5:10 paolo
2002-06-17 2:16 paolo
2002-06-17 2:13 steev
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).