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)); | ^~~~~~~~~~~