public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Avoid -Wmaybe-uninitialized warning in std::stop_source [PR109339]
@ 2023-03-31 14:50 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-03-31 14:50 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested powerpc64le-linux. Pushed to trunk.

-- >8 --

We pass a const-reference to *this before it's constructed, and GCC
assumes that all const-references are accessed. Add the access attribute
to say it's not accessed.

libstdc++-v3/ChangeLog:

	PR libstdc++/109339
	* include/std/stop_token (_Stop_state_ptr(const stop_source&)):
	Add attribute access with access-mode 'none'.
	* testsuite/30_threads/stop_token/stop_source/109339.cc: New test.
---
 libstdc++-v3/include/std/stop_token                    |  1 +
 .../30_threads/stop_token/stop_source/109339.cc        | 10 ++++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/30_threads/stop_token/stop_source/109339.cc

diff --git a/libstdc++-v3/include/std/stop_token b/libstdc++-v3/include/std/stop_token
index 76aef78a7ef..c90fc786b63 100644
--- a/libstdc++-v3/include/std/stop_token
+++ b/libstdc++-v3/include/std/stop_token
@@ -395,6 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       _Stop_state_ref() = default;
 
+      [[__gnu__::__access__(__none__, 2)]]
       explicit
       _Stop_state_ref(const stop_source&)
       : _M_ptr(new _Stop_state_t())
diff --git a/libstdc++-v3/testsuite/30_threads/stop_token/stop_source/109339.cc b/libstdc++-v3/testsuite/30_threads/stop_token/stop_source/109339.cc
new file mode 100644
index 00000000000..eea614eef80
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/stop_token/stop_source/109339.cc
@@ -0,0 +1,10 @@
+// { dg-options "-Wmaybe-uninitialized -Og -std=gnu++20" }
+// { dg-do compile { target c++20 } }
+
+#include <stop_token>
+
+int main()
+{
+  std::stop_source ss;
+ // { dg-bogus "uninitialized" "PR 109339" { target *-*-* } 0 }
+}
-- 
2.39.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-31 14:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-31 14:50 [committed] libstdc++: Avoid -Wmaybe-uninitialized warning in std::stop_source [PR109339] Jonathan Wakely

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