From: Jonathan Wakely Date: Fri, 7 Oct 2016 18:02:43 +0000 (+0100) Subject: Implement std::has_unique_object_representations X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=873c7d5ade8c018b0b2ab50c0ba232473bbf86ed;p=gcc.git Implement std::has_unique_object_representations * 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d9fa88af6e9..68f1b516647 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2016-10-07 Jonathan Wakely + + * 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 * doc/xml/manual/status_cxx2011.xml: Update status. diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml index 9f47b349834..f1d709ee071 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml @@ -441,14 +441,13 @@ Feature-testing recommendations for C++. - has_unique_object_representations P0258R2 - No + 7 __cpp_lib_has_unique_object_representations >= 201606 diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index cd0ba99dcb8..d402b5b496d 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3040,6 +3040,16 @@ template constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value; template constexpr bool is_convertible_v = is_convertible<_From, _To>::value; + +# define __cpp_lib_has_unique_object_representations 201606 + /// has_unique_object_representations + template + struct has_unique_object_representations + : bool_constant<__has_unique_object_representations( + remove_cv_t> + )> + { }; + #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 index 00000000000..29be714dabc --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_unique_object_representations/requirements/explicit_instantiation.cc @@ -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 +// . + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +namespace std +{ + typedef short test_type; + template struct has_unique_object_representations; +} 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 index 00000000000..e24a97291ca --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_unique_object_representations/requirements/typedefs.cc @@ -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 +// . + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +void test01() +{ + // Check for required typedefs + typedef std::has_unique_object_representations test_type; + static_assert( std::is_same::value ); + typedef std::integral_constant bool_type; + static_assert( std::is_same::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 index 00000000000..5a77ee5b52a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_unique_object_representations/value.cc @@ -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 +// . + +#include +#include + +void test01() +{ + using std::has_unique_object_representations; + using __gnu_test::test_category; + + // Positive tests. + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + + enum E : unsigned { }; + static_assert(test_category(true), ""); + + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + static_assert(test_category(true), ""); + static_assert(test_category(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(false), ""); + static_assert(test_category(false), ""); // implementation-defined + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); + static_assert(test_category(false), ""); +}