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: [EMAIL PROTECTED]:~$ 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