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.
This commit is contained in:
Jonathan Wakely
2023-03-31 13:38:14 +01:00
parent 10e573e86c
commit a35e8042fb
2 changed files with 11 additions and 0 deletions
+1
View File
@@ -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())
@@ -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 }
}