public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/27846]  New: global namespace is polluted
@ 2006-05-31 19:23 mbo at intec dot dk
  2006-05-31 19:24 ` [Bug libstdc++/27846] " mbo at intec dot dk
  2006-05-31 19:34 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: mbo at intec dot dk @ 2006-05-31 19:23 UTC (permalink / raw)
  To: gcc-bugs

Problem:
The following code fails to compile. The problem is that call to max is
ambiguous. It seems as if the compiler can also see std::max eventhough I have
not included the global namespace by using "using namespace std;" or by using
"using std::max;". I find this very odd, since the namespace faciliy should
allow us to define the same names without the risk of a name-clash.

#include <string>

using std::string;

template<typename T>
inline T max(const T& a, const T&b)
{ return a < b ? b : a; }

int main()
{
    string a("a"), b("b");
    max(a, b);
}

Compiler info:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --with-tune=i686 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)

System type:
Linux pcbmbo 2.6.16 #1 Thu May 4 11:51:04 CEST 2006 i686 GNU/Linux
(Debian/unstable)

Command line used to invoke the compiler:
g++ -std=c++98 -Wall -Werror -Wextra -pedantic-errors -Wfloat-equal -Wshadow
-Wconversion -Wold-style-cast

Error message:
mbo@pcbmbo:~$ g++ -std=c++98 -Wall -Werror -Wextra -pedantic-errors
-Wfloat-equal -Wshadow -Wconversion -Wold-style-cast mymax.cpp
mymax.cpp: In function 'int main()':
mymax.cpp:12: error: call of overloaded 'max(std::string&, std::string&)' is
ambiguous
mymax.cpp:6: note: candidates are: T max(const T&, const T&) [with T =
std::string]
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/bits/stl_algobase.h:206:
note:                 const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp =
std::string]


-- 
           Summary: global namespace is polluted
           Product: gcc
           Version: 4.0.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mbo at intec dot dk


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


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

* [Bug libstdc++/27846] global namespace is polluted
  2006-05-31 19:23 [Bug libstdc++/27846] New: global namespace is polluted mbo at intec dot dk
@ 2006-05-31 19:24 ` mbo at intec dot dk
  2006-05-31 19:34 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: mbo at intec dot dk @ 2006-05-31 19:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from mbo at intec dot dk  2006-05-31 19:24 -------
Created an attachment (id=11556)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11556&action=view)
Preprocessed source


-- 


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


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

* [Bug libstdc++/27846] global namespace is polluted
  2006-05-31 19:23 [Bug libstdc++/27846] New: global namespace is polluted mbo at intec dot dk
  2006-05-31 19:24 ` [Bug libstdc++/27846] " mbo at intec dot dk
@ 2006-05-31 19:34 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-05-31 19:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-05-31 19:34 -------
No, this has nothing to do with global namespace being polluted.  In fact this
is the correct behavior.  What is happening is you forgot about Argument
dependent lookup.


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2006-05-31 19:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-31 19:23 [Bug libstdc++/27846] New: global namespace is polluted mbo at intec dot dk
2006-05-31 19:24 ` [Bug libstdc++/27846] " mbo at intec dot dk
2006-05-31 19:34 ` pinskia at gcc dot gnu dot 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).