@@ -237,6 +237,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _ITp>
struct __atomic_base
{
+#if __cplusplus > 201402L
+ using value_type = _ITp;
+ using difference_type = value_type;
+#endif
+
private:
typedef _ITp __int_type;
@@ -62,6 +62,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<>
struct atomic<bool>
{
+#if __cplusplus > 201402L
+ using value_type = bool;
+#endif
+
private:
__atomic_base<bool> _M_base;
@@ -173,6 +177,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
struct atomic
{
+#if __cplusplus > 201402L
+ using value_type = _Tp;
+#endif
+
private:
// Align 1/2/4/8/16-byte types to at least their size.
static constexpr int _S_min_alignment
@@ -351,6 +359,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
struct atomic<_Tp*>
{
+#if __cplusplus > 201402L
+ using value_type = _Tp*;
+ using difference_type = ptrdiff_t;
+#endif
+
typedef _Tp* __pointer_type;
typedef __atomic_base<_Tp*> __base_type;
__base_type _M_b;
@@ -379,51 +392,111 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__pointer_type
operator++(int) noexcept
- { return _M_b++; }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b++;
+ }
__pointer_type
operator++(int) volatile noexcept
- { return _M_b++; }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b++;
+ }
__pointer_type
operator--(int) noexcept
- { return _M_b--; }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b--;
+ }
__pointer_type
operator--(int) volatile noexcept
- { return _M_b--; }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b--;
+ }
__pointer_type
operator++() noexcept
- { return ++_M_b; }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return ++_M_b;
+ }
__pointer_type
operator++() volatile noexcept
- { return ++_M_b; }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return ++_M_b;
+ }
__pointer_type
operator--() noexcept
- { return --_M_b; }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return --_M_b;
+ }
__pointer_type
operator--() volatile noexcept
- { return --_M_b; }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return --_M_b;
+ }
__pointer_type
operator+=(ptrdiff_t __d) noexcept
- { return _M_b.operator+=(__d); }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b.operator+=(__d);
+ }
__pointer_type
operator+=(ptrdiff_t __d) volatile noexcept
- { return _M_b.operator+=(__d); }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b.operator+=(__d);
+ }
__pointer_type
operator-=(ptrdiff_t __d) noexcept
- { return _M_b.operator-=(__d); }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b.operator-=(__d);
+ }
__pointer_type
operator-=(ptrdiff_t __d) volatile noexcept
- { return _M_b.operator-=(__d); }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b.operator-=(__d);
+ }
bool
is_lock_free() const noexcept
@@ -522,22 +595,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__pointer_type
fetch_add(ptrdiff_t __d,
memory_order __m = memory_order_seq_cst) noexcept
- { return _M_b.fetch_add(__d, __m); }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b.fetch_add(__d, __m);
+ }
__pointer_type
fetch_add(ptrdiff_t __d,
memory_order __m = memory_order_seq_cst) volatile noexcept
- { return _M_b.fetch_add(__d, __m); }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b.fetch_add(__d, __m);
+ }
__pointer_type
fetch_sub(ptrdiff_t __d,
memory_order __m = memory_order_seq_cst) noexcept
- { return _M_b.fetch_sub(__d, __m); }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b.fetch_sub(__d, __m);
+ }
__pointer_type
fetch_sub(ptrdiff_t __d,
memory_order __m = memory_order_seq_cst) volatile noexcept
- { return _M_b.fetch_sub(__d, __m); }
+ {
+#if __cplusplus > 201402L
+ static_assert( is_object<_Tp>::value, "pointer to object type" );
+#endif
+ return _M_b.fetch_sub(__d, __m);
+ }
};
@@ -27,4 +27,4 @@ struct X {
char stuff[0]; // GNU extension, type has zero size
};
-std::atomic<X> a; // { dg-error "not supported" "" { target *-*-* } 190 }
+std::atomic<X> a; // { dg-error "not supported" "" { target *-*-* } 198 }
new file mode 100644
@@ -0,0 +1,79 @@
+// Copyright (C) 2017 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++17" }
+// { dg-do compile { target c++1z } }
+
+#include <atomic>
+
+void
+test01()
+{
+ std::atomic<void*> p;
+ p.fetch_add(1); // { dg-error "from here" }
+ p.fetch_sub(1); // { dg-error "from here" }
+ p += 1; // { dg-error "from here" }
+ p -= 1; // { dg-error "from here" }
+ ++p; // { dg-error "from here" }
+ p++; // { dg-error "from here" }
+ --p; // { dg-error "from here" }
+ p--; // { dg-error "from here" }
+}
+
+void
+test02()
+{
+ std::atomic<void(*)()> p;
+ p.fetch_add(1); // { dg-error "from here" }
+ p.fetch_sub(1); // { dg-error "from here" }
+ p += 1; // { dg-error "from here" }
+ p -= 1; // { dg-error "from here" }
+ ++p; // { dg-error "from here" }
+ p++; // { dg-error "from here" }
+ --p; // { dg-error "from here" }
+ p--; // { dg-error "from here" }
+}
+
+void
+test03()
+{
+ volatile std::atomic<void*> p;
+ p.fetch_add(1); // { dg-error "from here" }
+ p.fetch_sub(1); // { dg-error "from here" }
+ p += 1; // { dg-error "from here" }
+ p -= 1; // { dg-error "from here" }
+ ++p; // { dg-error "from here" }
+ p++; // { dg-error "from here" }
+ --p; // { dg-error "from here" }
+ p--; // { dg-error "from here" }
+}
+
+void
+test04()
+{
+ volatile std::atomic<void(*)()> p;
+ p.fetch_add(1); // { dg-error "from here" }
+ p.fetch_sub(1); // { dg-error "from here" }
+ p += 1; // { dg-error "from here" }
+ p -= 1; // { dg-error "from here" }
+ ++p; // { dg-error "from here" }
+ p++; // { dg-error "from here" }
+ --p; // { dg-error "from here" }
+ p--; // { dg-error "from here" }
+}
+
+// { dg-prune-output "static assertion failed" }
@@ -1,4 +1,4 @@
-// { dg-do run { target c++11 } }
+// { dg-do run { target { c++11_only || c++14_only } } }
// { dg-require-atomic-builtins "" }
// Copyright (C) 2012-2017 Free Software Foundation, Inc.
new file mode 100644
@@ -0,0 +1,35 @@
+// Copyright (C) 2017 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++17" }
+// { dg-do compile { target c++1z } }
+
+#include <atomic>
+
+template<typename T>
+constexpr bool check()
+{
+ typename std::atomic<T>::value_type* pv = (T*)nullptr;
+ typename std::atomic<T>::difference_type* pd = (std::ptrdiff_t*)nullptr;
+ return true;
+}
+
+static_assert( check<int*>(), "" );
+static_assert( check<void*>(), "" );
+static_assert( check<void(*)()>(), "" );
+struct X { };
+static_assert( check<X*>(), "" );
new file mode 100644
@@ -0,0 +1,38 @@
+// Copyright (C) 2017 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++17" }
+// { dg-do compile { target c++1z } }
+
+#include <atomic>
+
+template<typename T>
+constexpr bool check()
+{
+ typename std::atomic<T>::value_type* pv = (T*)nullptr;
+ typename std::atomic<T>::difference_type* pd = (T*)nullptr;
+ return true;
+}
+
+static_assert( check<signed short>(), "" );
+static_assert( check<unsigned short>(), "" );
+static_assert( check<signed int>(), "" );
+static_assert( check<unsigned int>(), "" );
+static_assert( check<signed long>(), "" );
+static_assert( check<unsigned long>(), "" );
+static_assert( check<signed long long>(), "" );
+static_assert( check<unsigned long long>(), "" );