public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace.
@ 2013-07-25 14:45 yangzhe1990 at gmail dot com
  2013-07-25 14:46 ` [Bug c++/57986] " yangzhe1990 at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: yangzhe1990 at gmail dot com @ 2013-07-25 14:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57986
           Summary: call to local "bind" template function called
                    std::bind without "using" any namespace.
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yangzhe1990 at gmail dot com

Source codes are attached.

The compiling cmdline is:
  g++ numeric_utils_test.cpp -std=c++11 -o numeric_utils_test -g -pedantic
-Wall -Wextra -Wconversion -lpthread

I've defined a thread class, a bind function, a vector_iterator_asdf, a
computation function, and the multi-thread counterpart of the same function in
my own namespace.

In the multi-threaded function, it calls my thread(bind(single_thread_function,
params)). Then interesting thing happens: If I omit a parameter to the bind
function, the compiling error message shows that std::bind was called instead
of telling me it's impossible to find the right bind function. But I don't have
any "using namespace std" in my code.

The vector_iterator_asdf class is a iterator of multi-dimensional mathematical
vectors stored in an array.

It seems that <iterator> somehow depend on <functional> so that std::bind is
introduced.

More interesting thing is that: if I comment out the #include <algorithm> line,
the compiler returns to the correct behavior. Or if I don't have any
vector_iterator_asdf variables.

The more weird thing is: If I don't use any vector_iterator_asdf variables, and
don't #include <algorithm>, but create a temporary vector_iterator_asdf object,
call one of it's method, assign the return value to some other value, the
compiler behaves correctly.

I don't know why <iterator>, <algorithm> and my vector_iterator_asdf class
combined together could affect c++ function resolving.


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

* [Bug c++/57986] call to local "bind" template function called std::bind without "using" any namespace.
  2013-07-25 14:45 [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace yangzhe1990 at gmail dot com
@ 2013-07-25 14:46 ` yangzhe1990 at gmail dot com
  2013-07-25 14:46 ` yangzhe1990 at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: yangzhe1990 at gmail dot com @ 2013-07-25 14:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from yangzhe1990 at gmail dot com ---
Created attachment 30552
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30552&action=edit
thread


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

* [Bug c++/57986] call to local "bind" template function called std::bind without "using" any namespace.
  2013-07-25 14:45 [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace yangzhe1990 at gmail dot com
  2013-07-25 14:46 ` [Bug c++/57986] " yangzhe1990 at gmail dot com
@ 2013-07-25 14:46 ` yangzhe1990 at gmail dot com
  2013-07-25 14:47 ` yangzhe1990 at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: yangzhe1990 at gmail dot com @ 2013-07-25 14:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from yangzhe1990 at gmail dot com ---
Created attachment 30553
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30553&action=edit
vector_iterator_asdf and computation functions


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

* [Bug c++/57986] call to local "bind" template function called std::bind without "using" any namespace.
  2013-07-25 14:45 [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace yangzhe1990 at gmail dot com
  2013-07-25 14:46 ` [Bug c++/57986] " yangzhe1990 at gmail dot com
  2013-07-25 14:46 ` yangzhe1990 at gmail dot com
@ 2013-07-25 14:47 ` yangzhe1990 at gmail dot com
  2013-07-25 14:50 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: yangzhe1990 at gmail dot com @ 2013-07-25 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from yangzhe1990 at gmail dot com ---
Created attachment 30554
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30554&action=edit
main program


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

* [Bug c++/57986] call to local "bind" template function called std::bind without "using" any namespace.
  2013-07-25 14:45 [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace yangzhe1990 at gmail dot com
                   ` (2 preceding siblings ...)
  2013-07-25 14:47 ` yangzhe1990 at gmail dot com
@ 2013-07-25 14:50 ` redi at gcc dot gnu.org
  2013-07-25 14:51 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2013-07-25 14:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to yangzhe1990 from comment #0)
> Then interesting thing
> happens: If I omit a parameter to the bind function, the compiling error
> message shows that std::bind was called instead of telling me it's
> impossible to find the right bind function. But I don't have any "using
> namespace std" in my code.

Surely it's finding it via ADL,
http://en.wikipedia.org/wiki/Argument-dependent_name_lookup

> It seems that <iterator> somehow depend on <functional> so that std::bind is
> introduced.

That's allowed by the standard.

Please reduce the code to something smaller, I don't believe three separate
files are necessary to reproduce it.


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

* [Bug c++/57986] call to local "bind" template function called std::bind without "using" any namespace.
  2013-07-25 14:45 [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace yangzhe1990 at gmail dot com
                   ` (3 preceding siblings ...)
  2013-07-25 14:50 ` redi at gcc dot gnu.org
@ 2013-07-25 14:51 ` redi at gcc dot gnu.org
  2013-07-25 14:52 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2013-07-25 14:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
        thread(const thread &X) {
            swap(const_cast<struct thread &>(X));
        }

This is insane, don't do that.


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

* [Bug c++/57986] call to local "bind" template function called std::bind without "using" any namespace.
  2013-07-25 14:45 [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace yangzhe1990 at gmail dot com
                   ` (4 preceding siblings ...)
  2013-07-25 14:51 ` redi at gcc dot gnu.org
@ 2013-07-25 14:52 ` redi at gcc dot gnu.org
  2013-07-25 15:55 ` yangzhe1990 at gmail dot com
  2013-07-25 16:11 ` yangzhe1990 at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2013-07-25 14:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
    class vector_iterator_asdf :
        public std::iterator<std::random_access_iterator_tag, T *,
                     std::ptrdiff_t, T *const *, T *const &> {

vector_iterator_asdf has a base class defined in namespace std, therefore that
is an associated namespace and so an unqualified call to bind() with an
argument of type vector_iterator_asdf can find std::bind via ADL.


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

* [Bug c++/57986] call to local "bind" template function called std::bind without "using" any namespace.
  2013-07-25 14:45 [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace yangzhe1990 at gmail dot com
                   ` (5 preceding siblings ...)
  2013-07-25 14:52 ` redi at gcc dot gnu.org
@ 2013-07-25 15:55 ` yangzhe1990 at gmail dot com
  2013-07-25 16:11 ` yangzhe1990 at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: yangzhe1990 at gmail dot com @ 2013-07-25 15:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from yangzhe1990 at gmail dot com ---
Thanks. Now only one question left. Why removing <algorithm> could disable the
ADL?

BTW, in c++03, to avoid the const_cast, is writing a shared_ptr the right
choice?


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

* [Bug c++/57986] call to local "bind" template function called std::bind without "using" any namespace.
  2013-07-25 14:45 [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace yangzhe1990 at gmail dot com
                   ` (6 preceding siblings ...)
  2013-07-25 15:55 ` yangzhe1990 at gmail dot com
@ 2013-07-25 16:11 ` yangzhe1990 at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: yangzhe1990 at gmail dot com @ 2013-07-25 16:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from yangzhe1990 at gmail dot com ---
> <algorithm> is probably including <functional>

Yes, you are right. <iterator> is not including <functional>.

> Make the type non-copyable, and if you need to pass it around then use
> shared_ptr<thread>

Thanks. Anyway there seems no way to do { thread a; ... ; a =
thread(some_function); } .


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

end of thread, other threads:[~2013-07-25 16:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-25 14:45 [Bug c++/57986] New: call to local "bind" template function called std::bind without "using" any namespace yangzhe1990 at gmail dot com
2013-07-25 14:46 ` [Bug c++/57986] " yangzhe1990 at gmail dot com
2013-07-25 14:46 ` yangzhe1990 at gmail dot com
2013-07-25 14:47 ` yangzhe1990 at gmail dot com
2013-07-25 14:50 ` redi at gcc dot gnu.org
2013-07-25 14:51 ` redi at gcc dot gnu.org
2013-07-25 14:52 ` redi at gcc dot gnu.org
2013-07-25 15:55 ` yangzhe1990 at gmail dot com
2013-07-25 16:11 ` yangzhe1990 at gmail dot com

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).