public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Giuliano Belinassi <giulianob@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/autopar_devel] libstdc++: Make std::atomic_flag::test members const Date: Sat, 22 Aug 2020 22:30:36 +0000 (GMT) [thread overview] Message-ID: <20200822223036.C9D4C3870895@sourceware.org> (raw) https://gcc.gnu.org/g:1115e1732174d50d38354163fef132d60bf04949 commit 1115e1732174d50d38354163fef132d60bf04949 Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Jun 12 10:22:05 2020 +0100 libstdc++: Make std::atomic_flag::test members const Also fix the tests so they run without an explicit -std=gnu++2a in the RUNTESTFLAGS, and test the new function on const-qualified objects. * include/bits/atomic_base.h (atomic_flag::test): Add missing const qualifiers. * testsuite/29_atomics/atomic_flag/test/explicit.cc: Add dg-options and verify results of test function. * testsuite/29_atomics/atomic_flag/test/implicit.cc: Likewise. Diff: --- libstdc++-v3/include/bits/atomic_base.h | 4 ++-- .../testsuite/29_atomics/atomic_flag/test/explicit.cc | 16 ++++++++++++---- .../testsuite/29_atomics/atomic_flag/test/implicit.cc | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index 01f77a0f372..ebcfeb4d51a 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -212,7 +212,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #define __cpp_lib_atomic_flag_test 201907L _GLIBCXX_ALWAYS_INLINE bool - test(memory_order __m = memory_order_seq_cst) noexcept + test(memory_order __m = memory_order_seq_cst) const noexcept { __atomic_flag_data_type __v; __atomic_load(&_M_i, &__v, int(__m)); @@ -220,7 +220,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } _GLIBCXX_ALWAYS_INLINE bool - test(memory_order __m = memory_order_seq_cst) volatile noexcept + test(memory_order __m = memory_order_seq_cst) const volatile noexcept { __atomic_flag_data_type __v; __atomic_load(&_M_i, &__v, int(__m)); diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc index 539656ba583..4f2a10d6d40 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc @@ -1,3 +1,4 @@ +// { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } // { dg-require-thread-fence "" } @@ -19,14 +20,21 @@ // <http://www.gnu.org/licenses/>. #include <atomic> +#include <testsuite_hooks.h> int main() { using namespace std; - atomic_flag af = ATOMIC_FLAG_INIT; - if (af.test(memory_order_acquire)) - af.clear(memory_order_release); + atomic_flag af0 = ATOMIC_FLAG_INIT; + VERIFY( ! af0.test(memory_order_acquire) ); - return 0; + atomic_flag af{true}; + const atomic_flag& caf = af; + + VERIFY( af.test(memory_order_acquire) ); + VERIFY( caf.test(memory_order_acquire) ); + af.clear(memory_order_release); + VERIFY( ! af.test(memory_order_acquire) ); + VERIFY( ! caf.test(memory_order_acquire) ); } diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc index 11d29ac0b9e..3889f32b98a 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc @@ -1,3 +1,4 @@ +// { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } // { dg-require-thread-fence "" } @@ -19,14 +20,21 @@ // <http://www.gnu.org/licenses/>. #include <atomic> +#include <testsuite_hooks.h> int main() { using namespace std; - atomic_flag af = ATOMIC_FLAG_INIT; - if (af.test()) - af.clear(); + atomic_flag af0 = ATOMIC_FLAG_INIT; + VERIFY( ! af0.test(memory_order_acquire) ); - return 0; + atomic_flag af{true}; + const atomic_flag& caf = af; + + VERIFY( af.test() ); + VERIFY( caf.test() ); + af.clear(); + VERIFY( ! af.test() ); + VERIFY( ! caf.test() ); }
reply other threads:[~2020-08-22 22:30 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=20200822223036.C9D4C3870895@sourceware.org \ --to=giulianob@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: linkBe 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).