aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2023-03-31 13:38:14 +0100
committerJonathan Wakely <jwakely@redhat.com>2023-03-31 14:20:52 +0100
commita35e8042fbc7a3eb9cece1fba4cdd3b6cdfb906f (patch)
treef9980df9ef35ce9d42deec52edbcc42c0435ed9a
parent10e573e86c6a1ed11df529288ed8fba97f876032 (diff)
downloadgcc-a35e8042fbc7a3eb9cece1fba4cdd3b6cdfb906f.zip
gcc-a35e8042fbc7a3eb9cece1fba4cdd3b6cdfb906f.tar.gz
gcc-a35e8042fbc7a3eb9cece1fba4cdd3b6cdfb906f.tar.bz2
libstdc++: Avoid -Wmaybe-uninitialized warning in std::stop_source [PR109339]
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.
-rw-r--r--libstdc++-v3/include/std/stop_token1
-rw-r--r--libstdc++-v3/testsuite/30_threads/stop_token/stop_source/109339.cc10
2 files changed, 11 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/stop_token b/libstdc++-v3/include/std/stop_token
index 76aef78..c90fc78 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 0000000..eea614e
--- /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 }
+}