Implement std::has_unique_object_representations
authorJonathan Wakely <jwakely@redhat.com>
Fri, 7 Oct 2016 18:02:43 +0000 (19:02 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 7 Oct 2016 18:02:43 +0000 (19:02 +0100)
* doc/xml/manual/status_cxx2017.xml: Update status.
* include/std/type_traits (has_unique_object_representations): Define.
* testsuite/20_util/has_unique_object_representations/value.cc: New.
* testsuite/20_util/has_unique_object_representations/requirements/
explicit_instantiation.cc: New.
* testsuite/20_util/has_unique_object_representations/requirements/
typedefs.cc: New.

From-SVN: r240868

libstdc++-v3/ChangeLog
libstdc++-v3/doc/xml/manual/status_cxx2017.xml
libstdc++-v3/include/std/type_traits
libstdc++-v3/testsuite/20_util/has_unique_object_representations/requirements/explicit_instantiation.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/has_unique_object_representations/requirements/typedefs.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/has_unique_object_representations/value.cc [new file with mode: 0644]

index d9fa88af6e9e07d7f6d01a02ce279c5befb8eb8e..68f1b516647eedbbc80ff02579020c70a123a604 100644 (file)
@@ -1,3 +1,13 @@
+2016-10-07  Jonathan Wakely  <jwakely@redhat.com>
+
+       * doc/xml/manual/status_cxx2017.xml: Update status.
+       * include/std/type_traits (has_unique_object_representations): Define.
+       * testsuite/20_util/has_unique_object_representations/value.cc: New.
+       * testsuite/20_util/has_unique_object_representations/requirements/
+       explicit_instantiation.cc: New.
+       * testsuite/20_util/has_unique_object_representations/requirements/
+       typedefs.cc: New.
+
 2016-10-06  Jonathan Wakely  <jwakely@redhat.com>
 
        * doc/xml/manual/status_cxx2011.xml: Update status.
index 9f47b3498345fd3f50240de7266dafcc68e0bc49..f1d709ee07142cb262bc410d9215ca82fbe354c3 100644 (file)
@@ -441,14 +441,13 @@ Feature-testing recommendations for C++</link>.
     </row>
 
     <row>
-      <?dbhtml bgcolor="#C8B0B0" ?>
       <entry> has_unique_object_representations </entry>
       <entry>
        <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0258r2.html">
        P0258R2
        </link>
       </entry>
-      <entry align="center"> No </entry>
+      <entry align="center"> 7 </entry>
       <entry><code> __cpp_lib_has_unique_object_representations >= 201606 </code></entry>
     </row>
 
index cd0ba99dcb8c4f5f36df032c2f08876e5b5ee201..d402b5b496dbb40a333148fc7e32f37e23e92b75 100644 (file)
@@ -3040,6 +3040,16 @@ template <typename _Base, typename _Derived>
   constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value;
 template <typename _From, typename _To>
   constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
+
+# define __cpp_lib_has_unique_object_representations 201606
+  /// has_unique_object_representations
+  template<typename _Tp>
+    struct has_unique_object_representations
+    : bool_constant<__has_unique_object_representations(
+      remove_cv_t<remove_all_extents_t<_Tp>>
+      )>
+    { };
+
 #endif // C++17
 
 _GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/testsuite/20_util/has_unique_object_representations/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/has_unique_object_representations/requirements/explicit_instantiation.cc
new file mode 100644 (file)
index 0000000..29be714
--- /dev/null
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++1z" }
+// { dg-do compile { target c++1z } }
+
+// 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 copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+namespace std
+{
+  typedef short test_type;
+  template struct has_unique_object_representations<test_type>;
+}
diff --git a/libstdc++-v3/testsuite/20_util/has_unique_object_representations/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/has_unique_object_representations/requirements/typedefs.cc
new file mode 100644 (file)
index 0000000..e24a972
--- /dev/null
@@ -0,0 +1,32 @@
+// { dg-options "-std=gnu++1z" }
+// { dg-do compile { target c++1z } }
+
+// 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 copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+void test01()
+{
+  // Check for required typedefs
+  typedef std::has_unique_object_representations<int>  test_type;
+  static_assert( std::is_same<test_type::value_type, bool>::value );
+  typedef std::integral_constant<bool, test_type{}()> bool_type;
+  static_assert( std::is_same<test_type::type, bool_type>::value );
+}
diff --git a/libstdc++-v3/testsuite/20_util/has_unique_object_representations/value.cc b/libstdc++-v3/testsuite/20_util/has_unique_object_representations/value.cc
new file mode 100644 (file)
index 0000000..5a77ee5
--- /dev/null
@@ -0,0 +1,110 @@
+// { dg-options "-std=gnu++1z" }
+// { dg-do compile { target c++1z } }
+
+// 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 copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <type_traits>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  using std::has_unique_object_representations;
+  using __gnu_test::test_category;
+
+  // Positive tests.
+  static_assert(test_category<has_unique_object_representations,
+               char>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               unsigned char>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               signed char>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               unsigned>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+                bool>(true), "");
+
+  enum E : unsigned { };
+  static_assert(test_category<has_unique_object_representations,
+               E>(true), "");
+
+  static_assert(test_category<has_unique_object_representations,
+               unsigned[3]>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               unsigned[3][2]>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               unsigned[]>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               unsigned[][2]>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               E[3]>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               E[3][2]>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               E[]>(true), "");
+  static_assert(test_category<has_unique_object_representations,
+               E[][2]>(true), "");
+
+  struct Padded {
+    char c1;
+    alignas(4) char c2;
+  };
+
+  struct Bitfield {
+    int i : 3;
+  };
+
+  struct Aligned {
+    alignas(4) char c;
+  };
+
+  // Negative tests.
+  static_assert(test_category<has_unique_object_representations,
+               void>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+                float>(false), ""); // implementation-defined
+  static_assert(test_category<has_unique_object_representations,
+               Padded>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Padded[2]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Padded[2][1]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Padded[]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Padded[][1]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Bitfield>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Bitfield[2]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Bitfield[2][1]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Bitfield[]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Bitfield[][1]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Aligned>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Aligned[2]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Aligned[2][1]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Aligned[]>(false), "");
+  static_assert(test_category<has_unique_object_representations,
+               Aligned[][1]>(false), "");
+}