diff mbox

[v3] Implement C++17 variable templates for type traits.

Message ID CAFk2RUai1gzyYV53m7ETaQOngvitWZkhieeK5OGJ9iOczwPckw@mail.gmail.com
State New
Headers show

Commit Message

Ville Voutilainen July 31, 2016, 12:50 p.m. UTC
On 31 July 2016 at 14:53, Ville Voutilainen <ville.voutilainen@gmail.com> wrote:
>> Somebody didn't run the whole testsuite.
> I will send a patch shortly.

I'm finishing testing this patch on Linux-PPC64.

2016-07-31  Ville Voutilainen  <ville.voutilainen@gmail.com>

    Add missing variable traits, fix testsuite failures.
    * include/bits/uses_allocator.h (uses_allocator_v): New.
    * include/std/functional (is_bind_expression_v, is_placeholder_v):
    Likewise.
    * testsuite/20_util/bind/is_placeholder_v.cc: Likewise.
    * testsuite/20_util/declval/requirements/1_neg.cc: Adjust.
    * testsuite/20_util/duration/literals/range.cc: Likewise.
    * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Likewise.
    * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Likewise.
    * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Likewise.
    * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Likewise.
    * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
    Likewise.
    * testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Likewise.
    * testsuite/20_util/uses_allocator/requirements/uses_allocator_v.cc:
    New.

Comments

Jonathan Wakely July 31, 2016, 1:12 p.m. UTC | #1
On 31/07/16 15:50 +0300, Ville Voutilainen wrote:
>diff --git a/libstdc++-v3/include/bits/uses_allocator.h b/libstdc++-v3/include/bits/uses_allocator.h
>index b1ff58a..8fdeda7 100644
>--- a/libstdc++-v3/include/bits/uses_allocator.h
>+++ b/libstdc++-v3/include/bits/uses_allocator.h
>@@ -108,8 +108,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>       __ret._M_a = std::__addressof(__a);
>       return __ret;
>     }
>+#if __cplusplus > 201402L
>+  template <typename _Tp, typename _Alloc>
>+    constexpr bool uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
>+#endif // C++17
>
>-_GLIBCXX_END_NAMESPACE_VERSION
>+  _GLIBCXX_END_NAMESPACE_VERSION

This has become indented, but the corresponding BEGIN isn't indented,
so please restore the indentation.


>diff --git a/libstdc++-v3/testsuite/20_util/bind/is_placeholder_v.cc b/libstdc++-v3/testsuite/20_util/bind/is_placeholder_v.cc
>new file mode 100644
>index 0000000..ef66883
>--- /dev/null
>+++ b/libstdc++-v3/testsuite/20_util/bind/is_placeholder_v.cc
>@@ -0,0 +1,37 @@
>+// { dg-options "-std=gnu++17" }
>+// { dg-do compile }
>+
>+// Copyright (C) 2014-2016 Free Software Foundation, Inc.

This should be just 2016.

Assuming testing passes, OK with those changes

Thanks for the quick fix.
diff mbox

Patch

diff --git a/libstdc++-v3/include/bits/uses_allocator.h b/libstdc++-v3/include/bits/uses_allocator.h
index b1ff58a..8fdeda7 100644
--- a/libstdc++-v3/include/bits/uses_allocator.h
+++ b/libstdc++-v3/include/bits/uses_allocator.h
@@ -108,8 +108,12 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       __ret._M_a = std::__addressof(__a);
       return __ret;
     }
+#if __cplusplus > 201402L
+  template <typename _Tp, typename _Alloc>
+    constexpr bool uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
+#endif // C++17
 
-_GLIBCXX_END_NAMESPACE_VERSION
+  _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
 #endif
diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional
index 0fdf043..97745ae 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -682,6 +682,13 @@  _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
     : public integral_constant<int, 0>
     { };
 
+#if __cplusplus > 201402L
+  template <typename _Tp> constexpr bool is_bind_expression_v
+    = is_bind_expression<_Tp>::value;
+  template <typename _Tp> constexpr int is_placeholder_v
+    = is_placeholder<_Tp>::value;
+#endif // C++17
+
   /** @brief The type of placeholder objects defined by libstdc++.
    *  @ingroup binders
    */
diff --git a/libstdc++-v3/testsuite/20_util/bind/is_placeholder_v.cc b/libstdc++-v3/testsuite/20_util/bind/is_placeholder_v.cc
new file mode 100644
index 0000000..ef66883
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/bind/is_placeholder_v.cc
@@ -0,0 +1,37 @@ 
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2014-2016 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 moved_to of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <functional>
+
+struct X
+{
+  int operator()() const { return 0; }
+  int operator()() volatile { return 1; }
+  int operator()() const volatile { return 2; }
+  void operator()() { };
+};
+
+static_assert( std::is_placeholder<decltype(std::placeholders::_1)>::value
+	       == std::is_placeholder_v<decltype(std::placeholders::_1)>);
+
+const auto b0 = std::bind(X());
+static_assert( std::is_bind_expression<decltype(b0)>::value
+	       == std::is_bind_expression_v<decltype(b0)>);
+
diff --git a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc
index 72246b8..558b8c6 100644
--- a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc
@@ -19,7 +19,7 @@ 
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "static assertion failed" "" { target *-*-* } 2259 }
+// { dg-error "static assertion failed" "" { target *-*-* } 2272 }
 
 #include <utility>
 
diff --git a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc b/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
index dbb4af1..6fe4bde 100644
--- a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
@@ -27,5 +27,5 @@  test01()
 
   // std::numeric_limits<int64_t>::max() == 9223372036854775807;
   auto h = 9223372036854775808h;
-  // { dg-error "cannot be represented" "" { target *-*-* } 796 }
+  // { dg-error "cannot be represented" "" { target *-*-* } 800 }
 }
diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc
index 14814b4..731a4a7 100644
--- a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc
@@ -31,5 +31,5 @@  void test01()
   test_type d;
 }
 
-// { dg-error "rep cannot be a duration" "" { target *-*-* } 246 }
+// { dg-error "rep cannot be a duration" "" { target *-*-* } 250 }
 // { dg-error "required from here" "" { target *-*-* } 31 }
diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc
index a71a889..c32b885 100644
--- a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc
@@ -32,5 +32,5 @@  void test01()
   test_type d;			// { dg-error "required from here" }
 }
 
-// { dg-error "must be a specialization of ratio" "" { target *-*-* } 247 }
+// { dg-error "must be a specialization of ratio" "" { target *-*-* } 251 }
 // { dg-prune-output "not a member" }
diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc
index 016dc81..2369440 100644
--- a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc
@@ -33,5 +33,5 @@  void test01()
   test_type d;
 }
 
-// { dg-error "period must be positive" "" { target *-*-* } 249 }
+// { dg-error "period must be positive" "" { target *-*-* } 253 }
 // { dg-error "required from here" "" { target *-*-* } 33 }
diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
index 7724579..5e8fc47 100644
--- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
@@ -48,4 +48,4 @@  void test01()
 // { dg-error "required from here" "" { target *-*-* } 40 }
 // { dg-error "required from here" "" { target *-*-* } 42 }
 
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1924 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1937 }
diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
index 75fadf4..52f89f3 100644
--- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
@@ -48,5 +48,5 @@  void test01()
 // { dg-error "required from here" "" { target *-*-* } 40 }
 // { dg-error "required from here" "" { target *-*-* } 42 }
 
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1820 }
-// { dg-error "declaration of" "" { target *-*-* } 1777 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1833 }
+// { dg-error "declaration of" "" { target *-*-* } 1790 }
diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
index 0efa556..1a6bc52 100644
--- a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
@@ -42,7 +42,7 @@  test02()
 // { dg-error "required from here" "" { target *-*-* } 29 }
 // { dg-error "expected initializer" "" { target *-*-* } 36 }
 // { dg-error "expected initializer" "" { target *-*-* } 38 }
-// { dg-error "overflow in addition" "" { target *-*-* } 435 }
+// { dg-error "overflow in addition" "" { target *-*-* } 451 }
 // { dg-error "overflow in multiplication" "" { target *-*-* } 97 }
 // { dg-error "overflow in multiplication" "" { target *-*-* } 99 }
 // { dg-error "overflow in multiplication" "" { target *-*-* } 101 }
diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/requirements/uses_allocator_v.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/requirements/uses_allocator_v.cc
new file mode 100644
index 0000000..cc6e790
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/uses_allocator/requirements/uses_allocator_v.cc
@@ -0,0 +1,29 @@ 
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2016 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 moved_to of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <memory>
+#include <string>
+
+using namespace std;
+
+static_assert(uses_allocator<int, allocator<int>>::value
+	      == uses_allocator_v<int, allocator<int>>);
+static_assert(uses_allocator<string, allocator<string>>::value
+	      == uses_allocator_v<string, allocator<string>>);