From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 4E1E6385771A; Thu, 27 Apr 2023 14:43:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E1E6385771A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682606634; bh=XV5yK8B24BLjg5sqW1vWEGBgrTcHiYd4/jEMNwBvPjg=; h=From:To:Subject:Date:From; b=xkyorkl/N32dmp7wDyvFvUoxPWEn92xY3kk9KkBSEb3S9DzTRcD2Y+HVjtb8BJXD/ fVJhhHiPES4m0x+LlEgkW9Frkxa2jh9i9AtoX2Vra8POVeXCs3UHN1acO4qW/JsiRq OKgAQvU+shlP/Rj33JyvObUXwmK3KekjbZ1xqhkM= 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 r12-9486] libstdc++: Avoid -Wmaybe-uninitialized warning in std::stop_source [PR109339] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: d8def0b55572fc5bc02a0fee6a98787cd50ee885 X-Git-Newrev: 47880309516fd5c913102eb4c52dc86da7051983 Message-Id: <20230427144354.4E1E6385771A@sourceware.org> Date: Thu, 27 Apr 2023 14:43:54 +0000 (GMT) List-Id: https://gcc.gnu.org/g:47880309516fd5c913102eb4c52dc86da7051983 commit r12-9486-g47880309516fd5c913102eb4c52dc86da7051983 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. (cherry picked from commit a35e8042fbc7a3eb9cece1fba4cdd3b6cdfb906f) 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 07d4fdafeb4..72fec183569 100644 --- a/libstdc++-v3/include/std/stop_token +++ b/libstdc++-v3/include/std/stop_token @@ -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 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 } +}