Implement p0258r2: has_unique_object_representations

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@321685 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__config b/include/__config
index 80bc993..a4dfc41 100644
--- a/include/__config
+++ b/include/__config
@@ -461,7 +461,11 @@
 #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 @@
 #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)
diff --git a/include/type_traits b/include/type_traits
index 92db181..7a6c992 100644
--- a/include/type_traits
+++ b/include/type_traits
@@ -132,6 +132,8 @@
 
     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 @@
         = 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 @@
     = 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
diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp
new file mode 100644
index 0000000..e4a3d20
--- /dev/null
+++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp
@@ -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[]>();
+
+}
diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html
index 4fd84f4..3154765 100644
--- a/www/cxx1z_status.html
+++ b/www/cxx1z_status.html
@@ -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 &lt;regex&gt; bits.</i></p>
+<p><i>The parts of P0607 that are not done are the &lt;regex&gt; bits.</i></p>
 
 <p><i>[ Note: "Nothing to do" means that no library changes were needed to implement this change -- end note]</i></p>