diff --git a/include/__config b/include/__config index 80bc9939a..a4dfc4173 100644 --- a/include/__config +++ b/include/__config @@ -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) diff --git a/include/type_traits b/include/type_traits index 92db181b9..7a6c99293 100644 --- a/include/type_traits +++ b/include/type_traits @@ -132,6 +132,8 @@ namespace std template struct has_virtual_destructor; + template struct has_unique_object_representations; // C++17 + // Relationships between types: template struct is_same; template struct is_base_of; @@ -355,6 +357,8 @@ namespace std = is_nothrow_destructible::value; // C++17 template inline constexpr bool has_virtual_destructor_v = has_virtual_destructor::value; // C++17 + template inline constexpr bool has_unique_object_representations_v // C++17 + = has_unique_object_representations::value; // See C++14 20.10.5, type property queries template 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; #endif +// has_unique_object_representations + +#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS) + +template struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations + : public integral_constant>)> {}; + +#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_unique_object_representations_v + = has_unique_object_representations<_Tp>::value; +#endif + +#endif + // alignment_of template 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 000000000..e4a3d203c --- /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 + +#include "test_macros.h" + +template +void test_has_unique_object_representations() +{ + static_assert( std::has_unique_object_representations::value, ""); + static_assert( std::has_unique_object_representations::value, ""); + static_assert( std::has_unique_object_representations::value, ""); + static_assert( std::has_unique_object_representations::value, ""); + + static_assert( std::has_unique_object_representations_v, ""); + static_assert( std::has_unique_object_representations_v, ""); + static_assert( std::has_unique_object_representations_v, ""); + static_assert( std::has_unique_object_representations_v, ""); +} + +template +void test_has_not_has_unique_object_representations() +{ + static_assert(!std::has_unique_object_representations::value, ""); + static_assert(!std::has_unique_object_representations::value, ""); + static_assert(!std::has_unique_object_representations::value, ""); + static_assert(!std::has_unique_object_representations::value, ""); + + static_assert(!std::has_unique_object_representations_v, ""); + static_assert(!std::has_unique_object_representations_v, ""); + static_assert(!std::has_unique_object_representations_v, ""); + static_assert(!std::has_unique_object_representations_v, ""); +} + +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(); + test_has_not_has_unique_object_representations(); + test_has_not_has_unique_object_representations(); + test_has_not_has_unique_object_representations(); + test_has_not_has_unique_object_representations(); + test_has_not_has_unique_object_representations(); + +// 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(); +// test_has_not_has_unique_object_representations(); +// test_has_not_has_unique_object_representations(); + + + test_has_unique_object_representations(); + test_has_unique_object_representations(); + test_has_unique_object_representations(); + test_has_unique_object_representations(); + +} diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 4fd84f471..315476522 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -113,7 +113,7 @@ p0209r2LWGmake_from_tuple: apply for constructionOuluComplete3.9 p0219r1LWGRelative Paths for FilesystemOulu p0254r2LWGIntegrating std::string_view and std::stringOuluComplete4.0 - p0258r2LWGhas_unique_object_representationsOulu + p0258r2LWGhas_unique_object_representationsOuluComplete6.0 p0295r0LWGAdopt Selected Library Fundamentals V2 Components for C++17OuluComplete4.0 p0302r1LWGRemoving Allocator Support in std::functionOuluComplete4.0 p0307r2LWGMaking Optional Greater Equal AgainOuluComplete4.0 @@ -171,7 +171,7 @@ -

The parts of P0607 that are not done are for has_unique_object_representations_v, plus the <regex> bits.

+

The parts of P0607 that are not done are the <regex> bits.

[ Note: "Nothing to do" means that no library changes were needed to implement this change -- end note]