Bug 48472 - some flavors of std::bind are included in the global namespace when you include <functional> with -std=c++0x
Summary: some flavors of std::bind are included in the global namespace when you inclu...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-05 21:16 UTC by Blaies Gassend
Modified: 2011-04-05 22:08 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Blaies Gassend 2011-04-05 21:16:57 UTC
The following program compiles correctly. I believe it should not because bind should not be in the global namespace. (If you take A out of std this program fails as one would expect.)

-------------------------------------
// Compile with: g++ test.cpp -std=c++0x -c
#include <functional>

namespace std
{
class A
{};
}

void f(std::A a)
{
  bind(&f, a);
}
-------------------------------------

Output of g++ -v:
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
Comment 1 Andrew Pinski 2011-04-05 21:22:03 UTC
No this is not in the global namespace but rather namelookup looks at std::bind when one of the arguments are in std namespace.

namespace std
{
class A
{};
}

namespace std
{
  template<typename A>
  void g(void (*a)(A), A);
}

void h(std::A a)
{
  g(&h, a);
}
Comment 2 Jonathan Wakely 2011-04-05 22:08:21 UTC
right, this is Argument Dependent Lookup and is a feature of C++