[Bug libstdc++/100612] std::jthread can't be initialized with a pointer to a member function taking a std::stop_token

2021-05-17 Thread jonathan.oconnor at protonmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100612

--- Comment #9 from Jonathan O'Connor  
---
I'd already figured out the workaround using a static member function calling
the non-static member function. But the lambda version is nicer!

[Bug libstdc++/100612] std::jthread can't be initialized with a pointer to a member function taking a std::stop_token

2021-05-16 Thread jonathan.oconnor at protonmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100612

--- Comment #7 from Jonathan O'Connor  
---
libstdc++. Woops, apologies!

I feel somewhat vindicated by your non __STRICT_ANSI__ change!
I'll now go away and write the proposal. Thanks for the encouragement.

[Bug libstdc++/100612] std::jthread can't be initialized with a pointer to a member function taking a std::stop_token

2021-05-15 Thread jonathan.oconnor at protonmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100612

--- Comment #5 from Jonathan O'Connor  
---
I was afraid you were going to say it's not a bug :-) That's why I reached out
to Nico, who was on the committee, and was one of the people who proposed
jthread.

My view, as a user, is that jthread should be a drop in replacement for thread,
with auto-joining and stop_token support.

I've just reread the descripton of jthread's constructor here:
https://en.cppreference.com/w/cpp/thread/jthread/jthread
and it does seem to explicitly exclude the behaviour I would like.

So, I have no problem with you closing this as not a bug.
Sorry for wasting your time. I guess, I'll have to write a committee proposal.

BTW, thanks for your all your work on g++ and the stdlib++. Much appreciated.

[Bug libstdc++/100612] std::jthread can't be initialized with a pointer to a member function taking a std::stop_token

2021-05-15 Thread jonathan.oconnor at protonmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100612

--- Comment #1 from Jonathan O'Connor  
---
The std::jthread constructor does not support taking a pointer to a member
function that has, as a first argument, a std::stop_token.

In C++20, the new jthread class can accept a std::stop_token to aid in stopping
a thread cooperatively. Unfortunately, the library code in gcc 10.2.0 and all
later versions (according to godbolt.org) do not allow a member function taking
a stop_token to be used to initialize a jthread.

The problem is due to the std::jthread::_S_create() method which can't handle
my desired case.

In a private email discussion with Nico Josuttis, his opinion was this should
be allowed by the standard:
  "well, my rough understanding is that as INVOKE is called
  (see 20.9.2 Requirements [func.require] in the Standard),
  you can always pass a member function with the object to call the member
  function for as next argument.
  That should work for both thread and jthread."

The fix should be relatively simple, involving a further if constexpr check for
the Callable being a member function. I'll try and make a patch, and append it
here.

#include 

struct ThreadObj {
void withoutStopToken() {}
void withStopToken(std::stop_token st) {}
};

int main() {
ThreadObj obj;
// The following line causes an error. The other example compile fine.
std::jthread t1{&ThreadObj::withStopToken, &obj};
std::jthread t2{&ThreadObj::withoutStopToken, &obj};
return 0;
}

[Bug libstdc++/100612] New: std::jthread can't be initialized with a pointer to a member function taking a std::stop_token

2021-05-15 Thread jonathan.oconnor at protonmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100612

Bug ID: 100612
   Summary: std::jthread can't be initialized with a pointer to a
member function taking a std::stop_token
   Product: gcc
   Version: 10.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: jonathan.oconnor at protonmail dot com
  Target Milestone: ---

Created attachment 50817
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50817&action=edit
Sample source code showing error