@@ -139,6 +139,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _IntTp>
struct __atomic_base;
+#if __cplusplus <= 201703L
+# define _GLIBCXX20_INIT(I)
+#else
+# define __cpp_lib_atomic_value_initialization 201911L
+# define _GLIBCXX20_INIT(I) = I
+#endif
#define ATOMIC_VAR_INIT(_VI) { _VI }
@@ -169,7 +175,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __atomic_flag_base
{
- __atomic_flag_data_type _M_i;
+ __atomic_flag_data_type _M_i _GLIBCXX20_INIT({});
};
_GLIBCXX_END_EXTERN_C
@@ -267,7 +273,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static constexpr int _S_alignment =
sizeof(_ITp) > alignof(_ITp) ? sizeof(_ITp) : alignof(_ITp);
- alignas(_S_alignment) __int_type _M_i;
+ alignas(_S_alignment) __int_type _M_i _GLIBCXX20_INIT(0);
public:
__atomic_base() noexcept = default;
@@ -595,7 +601,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
private:
typedef _PTp* __pointer_type;
- __pointer_type _M_p;
+ __pointer_type _M_p _GLIBCXX20_INIT(nullptr);
// Factored out to facilitate explicit specialization.
constexpr ptrdiff_t
@@ -1175,8 +1181,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __atomic_impl::__sub_fetch_flt(&_M_fp, __i); }
private:
- alignas(_S_alignment) _Fp _M_fp;
+ alignas(_S_alignment) _Fp _M_fp _GLIBCXX20_INIT(0);
};
+#undef _GLIBCXX20_INIT
template<typename _Tp,
bool = is_integral_v<_Tp>, bool = is_floating_point_v<_Tp>>
@@ -165,6 +165,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return _M_base.compare_exchange_strong(__i1, __i2, __m); }
};
+#if __cplusplus <= 201703L
+# define _GLIBCXX20_INIT(I)
+#else
+# define _GLIBCXX20_INIT(I) = I
+#endif
/**
* @brief Generic atomic type, primary class template.
@@ -185,7 +190,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static constexpr int _S_alignment
= _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp);
- alignas(_S_alignment) _Tp _M_i;
+ alignas(_S_alignment) _Tp _M_i _GLIBCXX20_INIT(_Tp());
static_assert(__is_trivially_copyable(_Tp),
"std::atomic requires a trivially copyable type");
@@ -194,7 +199,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
"Incomplete or zero-sized types are not supported");
public:
- atomic() noexcept = default;
+ atomic() = default;
~atomic() noexcept = default;
atomic(const atomic&) = delete;
atomic& operator=(const atomic&) = delete;
@@ -348,7 +353,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return compare_exchange_strong(__e, __i, __m,
__cmpexch_failure_order(__m)); }
};
-
+#undef _GLIBCXX20_INIT
/// Partial specialization for pointer types.
template<typename _Tp>
@@ -164,6 +164,7 @@
#if __cplusplus > 201703L
// c++2a
#define __cpp_lib_atomic_ref 201806L
+#define __cpp_lib_atomic_value_initialization 201911L
#define __cpp_lib_bitops 201907L
#define __cpp_lib_bounded_array_traits 201902L
#if __cpp_concepts
@@ -27,5 +27,5 @@ int main()
return 0;
}
-// { dg-error "deleted" "" { target *-*-* } 639 }
+// { dg-error "deleted" "" { target *-*-* } 659 }
// { dg-prune-output "include" }
@@ -27,5 +27,5 @@ int main()
return 0;
}
-// { dg-error "deleted" "" { target *-*-* } 678 }
+// { dg-error "deleted" "" { target *-*-* } 698 }
// { dg-prune-output "include" }
new file mode 100644
@@ -0,0 +1,76 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <atomic>
+
+#ifndef __cpp_lib_atomic_value_initialization
+# error "Feature test macro for atomic value-initialization is missing"
+#elif __cpp_lib_atomic_value_initialization < 201911L
+# error "Feature test macro for atomic value-initialization has wrong value"
+#endif
+
+#include <testsuite_hooks.h>
+
+struct A
+{
+ constexpr A() : val(42) { }
+ int val;
+};
+
+constexpr std::atomic<A> a;
+
+void
+test01()
+{
+ VERIFY(a.load().val == 42);
+ static_assert(!std::is_nothrow_default_constructible_v<std::atomic<A>>);
+}
+
+struct B
+{
+ constexpr B() noexcept : val(99) { }
+ int val;
+};
+
+constexpr std::atomic<B> b;
+
+void
+test02()
+{
+ VERIFY(b.load().val == 99);
+ static_assert(std::is_nothrow_default_constructible_v<std::atomic<B>>);
+}
+
+constexpr std::atomic<int*> c;
+
+void
+test03()
+{
+ VERIFY(c.load() == nullptr);
+ static_assert(std::is_nothrow_default_constructible_v<std::atomic<int*>>);
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+}
new file mode 100644
@@ -0,0 +1,37 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <atomic>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::atomic_flag f;
+ VERIFY(!f.test_and_set());
+ VERIFY(f.test_and_set());
+ static_assert(std::is_nothrow_default_constructible_v<std::atomic_flag>);
+}
+
+int
+main()
+{
+ test01();
+}
@@ -22,6 +22,10 @@
void test01()
{
+#if __cplusplus <= 201703L
__gnu_test::has_trivial_cons_dtor test;
+#else
+ __gnu_test::has_trivial_dtor test;
+#endif
test.operator()<std::atomic_flag>();
}
@@ -25,7 +25,7 @@ test01()
{
using A = std::atomic<float>;
static_assert( std::is_standard_layout_v<A> );
- static_assert( std::is_trivially_default_constructible_v<A> );
+ static_assert( !std::is_trivially_default_constructible_v<A> );
static_assert( std::is_trivially_destructible_v<A> );
static_assert( std::is_same_v<A::value_type, float> );
static_assert( std::is_same_v<A::difference_type, A::value_type> );
@@ -41,7 +41,7 @@ test02()
{
using A = std::atomic<double>;
static_assert( std::is_standard_layout_v<A> );
- static_assert( std::is_trivially_default_constructible_v<A> );
+ static_assert( !std::is_trivially_default_constructible_v<A> );
static_assert( std::is_trivially_destructible_v<A> );
static_assert( std::is_same_v<A::value_type, double> );
static_assert( std::is_same_v<A::difference_type, A::value_type> );
@@ -57,7 +57,7 @@ test03()
{
using A = std::atomic<long double>;
static_assert( std::is_standard_layout_v<A> );
- static_assert( std::is_trivially_default_constructible_v<A> );
+ static_assert( !std::is_trivially_default_constructible_v<A> );
static_assert( std::is_trivially_destructible_v<A> );
static_assert( std::is_same_v<A::value_type, long double> );
static_assert( std::is_same_v<A::difference_type, A::value_type> );
new file mode 100644
@@ -0,0 +1,37 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <atomic>
+#include <testsuite_hooks.h>
+
+constexpr std::atomic<double> a;
+
+void
+test01()
+{
+ VERIFY(a.load() == 0);
+ static_assert(std::is_nothrow_default_constructible_v<std::atomic<double>>);
+}
+
+int
+main()
+{
+ test01();
+}
@@ -28,5 +28,5 @@ int main()
return 0;
}
-// { dg-error "deleted" "" { target *-*-* } 639 }
+// { dg-error "deleted" "" { target *-*-* } 659 }
// { dg-prune-output "include" }
@@ -28,5 +28,5 @@ int main()
return 0;
}
-// { dg-error "deleted" "" { target *-*-* } 678 }
+// { dg-error "deleted" "" { target *-*-* } 698 }
// { dg-prune-output "include" }
new file mode 100644
@@ -0,0 +1,37 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <atomic>
+#include <testsuite_hooks.h>
+
+constexpr std::atomic<int> a;
+
+void
+test01()
+{
+ VERIFY(a.load() == 0);
+ static_assert(std::is_nothrow_default_constructible_v<std::atomic<int>>);
+}
+
+int
+main()
+{
+ test01();
+}
@@ -22,7 +22,11 @@
void test01()
{
+#if __cplusplus <= 201703L
__gnu_test::has_trivial_cons_dtor test;
+#else
+ __gnu_test::has_trivial_dtor test;
+#endif
__gnu_cxx::typelist::apply_generator(test,
__gnu_test::atomic_integrals::type());
}
@@ -558,7 +558,6 @@ namespace __gnu_test
}
};
- // Generator to test standard layout
struct has_trivial_cons_dtor
{
template<typename _Tp>
@@ -582,6 +581,27 @@ namespace __gnu_test
}
};
+ struct has_trivial_dtor
+ {
+ template<typename _Tp>
+ void
+ operator()()
+ {
+ struct _Concept
+ {
+ void __constraint()
+ {
+ typedef std::is_trivially_destructible<_Tp> dtor_p;
+ static_assert(dtor_p::value, "destructor not trivial");
+ }
+ };
+
+ void (_Concept::*__x)() __attribute__((unused))
+ = &_Concept::__constraint;
+ }
+ };
+
+ // Generator to test standard layout
struct standard_layout
{
template<typename _Tp>