From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 075E03858018; Sat, 15 May 2021 12:43:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 075E03858018 From: "jonathan.oconnor at protonmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/100612] std::jthread can't be initialized with a pointer to a member function taking a std::stop_token Date: Sat, 15 May 2021 12:43:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jonathan.oconnor at protonmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 May 2021 12:43:09 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100612 --- 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 stop= ping a thread cooperatively. Unfortunately, the library code in gcc 10.2.0 and a= ll later versions (according to godbolt.org) do not allow a member function ta= king a stop_token to be used to initialize a jthread. The problem is due to the std::jthread::_S_create() method which can't hand= le my desired case. In a private email discussion with Nico Josuttis, his opinion was this shou= ld 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; }=