public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99403] New: Add header fix-it hints for std::this_thread::* and std::jthread
@ 2021-03-05  9:58 redi at gcc dot gnu.org
  2023-08-07 10:08 ` [Bug c++/99403] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-05  9:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

* [Bug c++/99403] Add header fix-it hints for std::this_thread::* and std::jthread
  2021-03-05  9:58 [Bug c++/99403] New: Add header fix-it hints for std::this_thread::* and std::jthread redi at gcc dot gnu.org
@ 2023-08-07 10:08 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2023-08-07 10:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99403

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-08-07
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

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

end of thread, other threads:[~2023-08-07 10:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05  9:58 [Bug c++/99403] New: Add header fix-it hints for std::this_thread::* and std::jthread redi at gcc dot gnu.org
2023-08-07 10:08 ` [Bug c++/99403] " redi at gcc dot gnu.org

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