public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99403] New: Add header fix-it hints for std::this_thread::* and std::jthread Date: Fri, 05 Mar 2021 09:58:24 +0000 [thread overview] Message-ID: <bug-99403-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99403 Bug ID: 99403 Summary: Add header fix-it hints for std::this_thread::* and std::jthread Product: gcc Version: 11.0 Status: UNCONFIRMED Keywords: diagnostic Severity: enhancement Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- #include <chrono> #include <future> int main() { std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_until(std::chrono::system_clock::now()); std::this_thread::get_id(); std::this_thread::yield(); } This fails with: ns.C: In function 'int main()': ns.C:5:21: error: 'sleep_for' is not a member of 'std::this_thread' 5 | std::this_thread::sleep_for(std::chrono::seconds(1)); | ^~~~~~~~~ ns.C:6:21: error: 'sleep_until' is not a member of 'std::this_thread' 6 | std::this_thread::sleep_until(std::chrono::system_clock::now()); | ^~~~~~~~~~~ We have a fix-it hint for std::thread, but not the other entities in <thread>: ns.C:2:1: note: 'std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'? 1 | #include <chrono> +++ |+#include <thread> 2 | int main() That should be added for std::jthread (since C++20 only), and namespace std::this_thread and the four functions in the example above (all for C++11 and later). There is no error for get_id and yield because they happen to be transitively included via <future>, but that's an implementation detail that could change in future (no pun intended). If <future> isn't included we get errors for std::this_thread itself, so that nested namespace deserves a fix-it hint of its own: #include <chrono> int main() { std::this_thread::sleep_for(std::chrono::seconds(1)); } ns.C: In function 'int main()': ns.C:4:8: error: 'std::this_thread' has not been declared 4 | std::this_thread::sleep_for(std::chrono::seconds(1)); | ^~~~~~~~~~~
next reply other threads:[~2021-03-05 9:58 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-05 9:58 redi at gcc dot gnu.org [this message] 2023-08-07 10:08 ` [Bug c++/99403] " redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-99403-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).