From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 8E8B2384B839; Fri, 31 Mar 2023 14:50:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E8B2384B839 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680274203; bh=SZJhZUa/fXphnXcsj4Ex3LJN25Wqq2QO3aCP7yb2mOU=; h=From:To:Subject:Date:From; b=LBXBtwaq2IEum4tgOyPlblgX+sLnrDlN1yFTzS8yKidZUuHST98N/l/rJXZBXAyY3 AfQ/KN2tKGH0jNc9Byiesc6g1sC9djr99WpGUS0T9KqqfH2JwF++hb6mciT8citepp k4LGohnQYxyUPPLG+/mVl9YHojWDicbJA4DdF2nQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-6958] libstdc++: Avoid -Wmaybe-uninitialized warning in std::stop_source [PR109339] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 10e573e86c6a1ed11df529288ed8fba97f876032 X-Git-Newrev: a35e8042fbc7a3eb9cece1fba4cdd3b6cdfb906f Message-Id: <20230331145003.8E8B2384B839@sourceware.org> Date: Fri, 31 Mar 2023 14:50:03 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a35e8042fbc7a3eb9cece1fba4cdd3b6cdfb906f commit r13-6958-ga35e8042fbc7a3eb9cece1fba4cdd3b6cdfb906f Author: Jonathan Wakely Date: Fri Mar 31 13:38:14 2023 +0100 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. Diff: --- libstdc++-v3/include/std/stop_token | 1 + .../testsuite/30_threads/stop_token/stop_source/109339.cc | 10 ++++++++++ 2 files changed, 11 insertions(+) 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 + +int main() +{ + std::stop_source ss; + // { dg-bogus "uninitialized" "PR 109339" { target *-*-* } 0 } +}