]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Avoid -Wmaybe-uninitialized warning in std::stop_source [PR109339]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 31 Mar 2023 12:38:14 +0000 (13:38 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 27 Apr 2023 14:42:02 +0000 (15:42 +0100)
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.

(cherry picked from commit a35e8042fbc7a3eb9cece1fba4cdd3b6cdfb906f)

libstdc++-v3/include/std/stop_token
libstdc++-v3/testsuite/30_threads/stop_token/stop_source/109339.cc [new file with mode: 0644]

index 07d4fdafeb4d980a59af8c12aaef117a0d2dff67..72fec183569e4f9049e8f2f1e2192197f0e44d06 100644 (file)
@@ -393,6 +393,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 (file)
index 0000000..eea614e
--- /dev/null
@@ -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 }
+}