Implement p0258r2: has_unique_object_representations
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@321685 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -464,6 +464,10 @@ namespace std {
|
|||||||
#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
|
#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !__is_identifier(__has_unique_object_representations)
|
||||||
|
#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(_LIBCPP_COMPILER_GCC)
|
#elif defined(_LIBCPP_COMPILER_GCC)
|
||||||
|
|
||||||
#define _ALIGNAS(x) __attribute__((__aligned__(x)))
|
#define _ALIGNAS(x) __attribute__((__aligned__(x)))
|
||||||
@@ -550,6 +554,10 @@ namespace std {
|
|||||||
#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
|
#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if _GNUC_VER >= 700
|
||||||
|
#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(_LIBCPP_COMPILER_MSVC)
|
#elif defined(_LIBCPP_COMPILER_MSVC)
|
||||||
|
|
||||||
#define _LIBCPP_TOSTRING2(x) #x
|
#define _LIBCPP_TOSTRING2(x) #x
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ namespace std
|
|||||||
|
|
||||||
template <class T> struct has_virtual_destructor;
|
template <class T> struct has_virtual_destructor;
|
||||||
|
|
||||||
|
template<class T> struct has_unique_object_representations; // C++17
|
||||||
|
|
||||||
// Relationships between types:
|
// Relationships between types:
|
||||||
template <class T, class U> struct is_same;
|
template <class T, class U> struct is_same;
|
||||||
template <class Base, class Derived> struct is_base_of;
|
template <class Base, class Derived> struct is_base_of;
|
||||||
@@ -355,6 +357,8 @@ namespace std
|
|||||||
= is_nothrow_destructible<T>::value; // C++17
|
= is_nothrow_destructible<T>::value; // C++17
|
||||||
template <class T> inline constexpr bool has_virtual_destructor_v
|
template <class T> inline constexpr bool has_virtual_destructor_v
|
||||||
= has_virtual_destructor<T>::value; // C++17
|
= 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
|
// See C++14 20.10.5, type property queries
|
||||||
template <class T> inline constexpr size_t alignment_of_v
|
template <class T> inline constexpr size_t alignment_of_v
|
||||||
@@ -1617,6 +1621,22 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_virtual_destructor_v
|
|||||||
= has_virtual_destructor<_Tp>::value;
|
= has_virtual_destructor<_Tp>::value;
|
||||||
#endif
|
#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
|
// alignment_of
|
||||||
|
|
||||||
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
|
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
|
||||||
|
|||||||
@@ -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[]>();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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/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/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/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/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/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>
|
<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> -->
|
<!-- <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> -->
|
||||||
</table>
|
</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>
|
<p><i>[ Note: "Nothing to do" means that no library changes were needed to implement this change -- end note]</i></p>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user