[libcxx] r321685 - Implement p0258r2: has_unique_object_representations

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 2 18:32:28 PST 2018


Author: marshall
Date: Tue Jan  2 18:32:28 2018
New Revision: 321685

URL: http://llvm.org/viewvc/llvm-project?rev=321685&view=rev
Log:
Implement p0258r2: has_unique_object_representations

Added:
    libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp
Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/type_traits
    libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=321685&r1=321684&r2=321685&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Tue Jan  2 18:32:28 2018
@@ -461,7 +461,11 @@ namespace std {
 #endif 
 
 #if __has_builtin(__builtin_launder)
-#define	_LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
+#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
+#endif
+
+#if !__is_identifier(__has_unique_object_representations)
+#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
 #endif
 
 #elif defined(_LIBCPP_COMPILER_GCC)
@@ -547,7 +551,11 @@ namespace std {
 #endif
 
 #if _GNUC_VER >= 700
-#define	_LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
+#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
+#endif
+
+#if _GNUC_VER >= 700
+#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
 #endif
 
 #elif defined(_LIBCPP_COMPILER_MSVC)

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=321685&r1=321684&r2=321685&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Tue Jan  2 18:32:28 2018
@@ -132,6 +132,8 @@ namespace std
 
     template <class T> struct has_virtual_destructor;
 
+    template<class T> struct has_unique_object_representations;         // C++17
+
     // Relationships between types:
     template <class T, class U> struct is_same;
     template <class Base, class Derived> struct is_base_of;
@@ -355,6 +357,8 @@ namespace std
         = is_nothrow_destructible<T>::value;                             // C++17
       template <class T> inline constexpr bool has_virtual_destructor_v
         = has_virtual_destructor<T>::value;                              // C++17
+      template<class T> inline constexpr bool has_unique_object_representations_v // C++17
+        = has_unique_object_representations<T>::value;
 
       // See C++14 20.10.5, type property queries
       template <class T> inline constexpr size_t alignment_of_v
@@ -1617,6 +1621,22 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR boo
     = has_virtual_destructor<_Tp>::value;
 #endif
 
+// has_unique_object_representations
+
+#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS)
+
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
+    : public integral_constant<bool, 
+       __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {};
+
+#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
+template <class _Tp>
+_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_unique_object_representations_v
+    = has_unique_object_representations<_Tp>::value;
+#endif
+
+#endif
+
 // alignment_of
 
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of

Added: libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp?rev=321685&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp (added)
+++ libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp Tue Jan  2 18:32:28 2018
@@ -0,0 +1,104 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// UNSUPPORTED: clang-3, clang-4, clang-5, apple-clang, gcc-4, gcc-5, gcc-6
+
+// type_traits
+
+// has_unique_object_representations
+
+#include <type_traits>
+
+#include "test_macros.h"
+
+template <class T>
+void test_has_unique_object_representations()
+{
+    static_assert( std::has_unique_object_representations<T>::value, "");
+    static_assert( std::has_unique_object_representations<const T>::value, "");
+    static_assert( std::has_unique_object_representations<volatile T>::value, "");
+    static_assert( std::has_unique_object_representations<const volatile T>::value, "");
+
+    static_assert( std::has_unique_object_representations_v<T>, "");
+    static_assert( std::has_unique_object_representations_v<const T>, "");
+    static_assert( std::has_unique_object_representations_v<volatile T>, "");
+    static_assert( std::has_unique_object_representations_v<const volatile T>, "");
+}
+
+template <class T>
+void test_has_not_has_unique_object_representations()
+{
+    static_assert(!std::has_unique_object_representations<T>::value, "");
+    static_assert(!std::has_unique_object_representations<const T>::value, "");
+    static_assert(!std::has_unique_object_representations<volatile T>::value, "");
+    static_assert(!std::has_unique_object_representations<const volatile T>::value, "");
+
+    static_assert(!std::has_unique_object_representations_v<T>, "");
+    static_assert(!std::has_unique_object_representations_v<const T>, "");
+    static_assert(!std::has_unique_object_representations_v<volatile T>, "");
+    static_assert(!std::has_unique_object_representations_v<const volatile T>, "");
+}
+
+class Empty
+{
+};
+
+class NotEmpty
+{
+    virtual ~NotEmpty();
+};
+
+union Union {};
+
+struct bit_zero
+{
+    int :  0;
+};
+
+class Abstract
+{
+    virtual ~Abstract() = 0;
+};
+
+struct A
+{
+    ~A();
+    unsigned foo;
+};
+
+struct B
+{
+   char bar;
+   int foo;
+};
+
+
+int main()
+{
+    test_has_not_has_unique_object_representations<void>();
+    test_has_not_has_unique_object_representations<Empty>();
+    test_has_not_has_unique_object_representations<NotEmpty>();
+    test_has_not_has_unique_object_representations<bit_zero>();
+    test_has_not_has_unique_object_representations<Abstract>();
+    test_has_not_has_unique_object_representations<B>();
+
+//  I would expect all three of these to have unique representations.
+//  I would also expect that there are systems where they do not.
+//     test_has_not_has_unique_object_representations<int&>();
+//     test_has_not_has_unique_object_representations<int *>();
+//     test_has_not_has_unique_object_representations<double>();
+
+
+    test_has_unique_object_representations<unsigned>();
+    test_has_unique_object_representations<Union>();
+    test_has_unique_object_representations<char[3]>();
+    test_has_unique_object_representations<char[]>();
+
+}

Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=321685&r1=321684&r2=321685&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Tue Jan  2 18:32:28 2018
@@ -113,7 +113,7 @@
 	<tr><td><a href="https://wg21.link/p0209r2">p0209r2</a></td><td>LWG</td><td>make_from_tuple: apply for construction</td><td>Oulu</td><td>Complete</td><td>3.9</td></tr>
 	<tr><td><a href="https://wg21.link/p0219r1">p0219r1</a></td><td>LWG</td><td>Relative Paths for Filesystem</td><td>Oulu</td><td></td><td></td></tr>
 	<tr><td><a href="https://wg21.link/p0254r2">p0254r2</a></td><td>LWG</td><td>Integrating std::string_view and std::string</td><td>Oulu</td><td>Complete</td><td>4.0</td></tr>
-	<tr><td><a href="https://wg21.link/p0258r2">p0258r2</a></td><td>LWG</td><td>has_unique_object_representations</td><td>Oulu</td><td></td><td></td></tr>
+	<tr><td><a href="https://wg21.link/p0258r2">p0258r2</a></td><td>LWG</td><td>has_unique_object_representations</td><td>Oulu</td><td>Complete</td><td>6.0</td></tr>
 	<tr><td><a href="https://wg21.link/p0295r0">p0295r0</a></td><td>LWG</td><td>Adopt Selected Library Fundamentals V2 Components for C++17</td><td>Oulu</td><td>Complete</td><td>4.0</td></tr>
 	<tr><td><a href="https://wg21.link/p0302r1">p0302r1</a></td><td>LWG</td><td>Removing Allocator Support in std::function</td><td>Oulu</td><td>Complete</td><td>4.0</td></tr>
 	<tr><td><a href="https://wg21.link/p0307r2">p0307r2</a></td><td>LWG</td><td>Making Optional Greater Equal Again</td><td>Oulu</td><td>Complete</td><td>4.0</td></tr>
@@ -171,7 +171,7 @@
 <!--  	<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> -->
   </table>
 
-<p><i>The parts of P0607 that are not done are for <tt>has_unique_object_representations_v</tt>, plus the <regex> bits.</i></p>
+<p><i>The parts of P0607 that are not done are the <regex> bits.</i></p>
 
 <p><i>[ Note: "Nothing to do" means that no library changes were needed to implement this change -- end note]</i></p>
 




More information about the cfe-commits mailing list