From: Paolo Carlini Date: Mon, 25 Apr 2011 23:04:16 +0000 (+0000) Subject: type_traits (struct underlying_type): Add. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a47407f631a14e4ad71c70442bec07df9ce732ab;p=gcc.git type_traits (struct underlying_type): Add. 2011-04-25 Paolo Carlini * include/std/type_traits (struct underlying_type): Add. * testsuite/20_util/underlying_type/requirements/typedefs-1.cc: New. * testsuite/20_util/underlying_type/requirements/typedefs-2.cc: Likewise. * testsuite/20_util/underlying_type/requirements/ explicit_instantiation.cc: Likewise. * testsuite/20_util/declval/requirements/1_neg.cc: Adjust dg-error line number. From-SVN: r172944 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9d767f5beef..9f39823f149 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2011-04-25 Paolo Carlini + + * include/std/type_traits (struct underlying_type): Add. + * testsuite/20_util/underlying_type/requirements/typedefs-1.cc: New. + * testsuite/20_util/underlying_type/requirements/typedefs-2.cc: + Likewise. + * testsuite/20_util/underlying_type/requirements/ + explicit_instantiation.cc: Likewise. + * testsuite/20_util/declval/requirements/1_neg.cc: Adjust dg-error + line number. + 2011-04-24 Paolo Carlini * include/parallel/multiway_merge.h: Uglify equally_split diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 11f1b012261..6d33416c330 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1581,7 +1581,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION common_type::type, _Vp...>::type type; }; - /// underlying_type (still unimplemented) + /// underlying_type + template + struct underlying_type + { + typedef __underlying_type(_Tp) type; + }; /// declval template diff --git a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc index debff581af5..af1522b7a40 100644 --- a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc +++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "static assertion failed" "" { target *-*-* } 1598 } +// { dg-error "static assertion failed" "" { target *-*-* } 1603 } #include diff --git a/libstdc++-v3/testsuite/20_util/underlying_type/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/underlying_type/requirements/explicit_instantiation.cc new file mode 100644 index 00000000000..159e9bd352c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/underlying_type/requirements/explicit_instantiation.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2011 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 enum E1 : unsigned { } test_type1; + typedef enum E2 : char { } test_type2; + typedef enum class E3 { } test_type3; + typedef enum class E4 : unsigned char { c = 1 } test_type4; + typedef enum class E5 : int { a = -1, b = 1 } test_type5; + typedef enum class E6 : long { c = __LONG_MAX__ } test_type6; + + template struct underlying_type; + template struct underlying_type; + template struct underlying_type; + template struct underlying_type; + template struct underlying_type; + template struct underlying_type; +} diff --git a/libstdc++-v3/testsuite/20_util/underlying_type/requirements/typedefs-1.cc b/libstdc++-v3/testsuite/20_util/underlying_type/requirements/typedefs-1.cc new file mode 100644 index 00000000000..777a646845e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/underlying_type/requirements/typedefs-1.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// +// Copyright (C) 2011 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() +{ + typedef enum E1 : unsigned { } test_type1; + typedef enum E2 : char { } test_type2; + typedef enum class E3 { } test_type3; + typedef enum class E4 : unsigned char { c = 1 } test_type4; + typedef enum class E5 : int { a = -1, b = 1 } test_type5; + typedef enum class E6 : long { c = __LONG_MAX__ } test_type6; + + // Check for required typedef + typedef std::underlying_type::type type1; + typedef std::underlying_type::type type2; + typedef std::underlying_type::type type3; + typedef std::underlying_type::type type4; + typedef std::underlying_type::type type5; + typedef std::underlying_type::type type6; +} diff --git a/libstdc++-v3/testsuite/20_util/underlying_type/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/20_util/underlying_type/requirements/typedefs-2.cc new file mode 100644 index 00000000000..b204a4f20a5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/underlying_type/requirements/typedefs-2.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// +// Copyright (C) 2011 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() +{ + using namespace std; + + enum E1 : unsigned { }; + enum E2 : char { }; + enum class E3 { }; + enum class E4 : unsigned char { c = 1 }; + enum class E5 : int { a = -1, b = 1 }; + enum class E6 : long { c = __LONG_MAX__ }; + + static_assert(is_same::type, unsigned>::value, "Error"); + static_assert(is_same::type, char>::value, "Error"); + static_assert(is_same::type, int>::value, "Error"); + static_assert(is_same::type, + unsigned char>::value, "Error"); + static_assert(is_same::type, int>::value, "Error"); + static_assert(is_same::type, long>::value, "Error"); +}