Bug 53872 - [C++11] ADL bug in std::thread
Summary: [C++11] ADL bug in std::thread
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.7.1
: P3 minor
Target Milestone: 4.7.2
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-06 12:12 UTC by frankhb1989
Modified: 2012-07-20 09:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-07-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description frankhb1989 2012-07-06 12:12:52 UTC
Code below fails to compile using mingw-g++4.7.1 from sourceforge.net/projects/mingwbuilds:

#include <thread>
#include <memory>
#include <functional>

template<typename, typename...P>
void make_shared(P&&...)
{}

struct C{}; // enable ADL

void f(C){}

int main()
{
	std::thread t(std::bind(&::f, C())); //error
}

Messages:

d:\mingw\bin\..\lib\gcc\i686-w64-mingw32\4.7.1\include\c++\thread||In instantiation of 'std::shared_ptr<std::thread::_Impl<_Callable> > std::thread::_M_make_routine(_Callable&&) [with _Callable = std::_Bind_simple<std::_Bind<void (*(C))(C)>()>]':|
d:\mingw\bin\..\lib\gcc\i686-w64-mingw32\4.7.1\include\c++\thread|133|required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = std::_Bind<void (*(C))(C)>; _Args = {}]'|
F:\Programing\Temp\T9.cpp|31|required from here|
d:\mingw\bin\..\lib\gcc\i686-w64-mingw32\4.7.1\include\c++\thread|191|sorry, unimplemented: use of 'type_pack_expansion' in template|
d:\mingw\bin\..\lib\gcc\i686-w64-mingw32\4.7.1\include\c++\thread|191|sorry, unimplemented: use of 'type_pack_expansion' in template|
d:\mingw\bin\..\lib\gcc\i686-w64-mingw32\4.7.1\include\c++\thread|191|error: call of overloaded 'make_shared(std::_Bind_simple<std::_Bind<void (*(C))(C)>()>)' is ambiguous|
d:\mingw\bin\..\lib\gcc\i686-w64-mingw32\4.7.1\include\c++\thread|191|note: candidates are:|
d:\mingw\bin\..\lib\gcc\i686-w64-mingw32\4.7.1\include\c++\bits\shared_ptr.h|611|note: std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = std::thread::_Impl<std::_Bind_simple<std::_Bind<void (*(C))(C)>()> >; _Args = {std::_Bind_simple<std::_Bind<void (*(C))(C)>()>}]|
F:\Programing\Temp\T9.cpp|22|note: void make_shared(P&& ...) [with <template-parameter-1-1> = std::thread::_Impl<std::_Bind_simple<std::_Bind<void (*(C))(C)>()> >; P = {std::_Bind_simple<std::_Bind<void (*(C))(C)>()>}]|

The line 191 of <thread>(in member template _M_make_routine):

return make_shared<_Impl<_Callable>>(std::forward<_Callable>(__f));

After I adding "std::" before "make_shared", it works fine.

Note: there is something wrong with the error message("unimplemented"). I'd file another bug for it.
Comment 1 Paolo Carlini 2012-07-06 13:09:28 UTC
Mine.
Comment 2 paolo@gcc.gnu.org 2012-07-06 13:56:04 UTC
Author: paolo
Date: Fri Jul  6 13:55:58 2012
New Revision: 189329

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189329
Log:
2012-07-06  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/53872
	* include/std/thread (thread::_M_make_routine): Qualify make_shared
	to prevent ADL.
	* testsuite/30_threads/thread/adl.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/30_threads/thread/adl.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/std/thread
Comment 3 paolo@gcc.gnu.org 2012-07-06 13:56:31 UTC
Author: paolo
Date: Fri Jul  6 13:56:24 2012
New Revision: 189330

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189330
Log:
2012-07-06  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/53872
	* include/std/thread (thread::_M_make_routine): Qualify make_shared
	to prevent ADL.
	* testsuite/30_threads/thread/adl.cc: New.

Added:
    branches/gcc-4_7-branch/libstdc++-v3/testsuite/30_threads/thread/adl.cc
Modified:
    branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_7-branch/libstdc++-v3/include/std/thread
Comment 4 Paolo Carlini 2012-07-06 13:59:27 UTC
Fixed mainline and 4.7.2.
Comment 5 Eric Botcazou 2012-07-20 07:13:27 UTC
The new test fails on older Solaris 8 versions:

Running target unix
FAIL: 30_threads/thread/adl.cc (test for excess errors)

I think you need to add:

// { dg-require-cstdint "" }
// { dg-require-gthreads "" }

like in the other tests, e.g id/hash.cc and id/operators.cc.
Comment 6 Paolo Carlini 2012-07-20 09:12:50 UTC
Oops, I'll fix it momentarily, thanks!