public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
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]
Date: Thu, 27 Apr 2023 14:43:54 +0000 (GMT)	[thread overview]
Message-ID: <20230427144354.4E1E6385771A@sourceware.org> (raw)

https://gcc.gnu.org/g:47880309516fd5c913102eb4c52dc86da7051983

commit r12-9486-g47880309516fd5c913102eb4c52dc86da7051983
Author: Jonathan Wakely <jwakely@redhat.com>
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 <stop_token>
+
+int main()
+{
+  std::stop_source ss;
+ // { dg-bogus "uninitialized" "PR 109339" { target *-*-* } 0 }
+}

                 reply	other threads:[~2023-04-27 14:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230427144354.4E1E6385771A@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).