type_traits (struct underlying_type): Add.
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 25 Apr 2011 23:04:16 +0000 (23:04 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 25 Apr 2011 23:04:16 +0000 (23:04 +0000)
2011-04-25  Paolo Carlini  <paolo.carlini@oracle.com>

* 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

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/type_traits
libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc
libstdc++-v3/testsuite/20_util/underlying_type/requirements/explicit_instantiation.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/underlying_type/requirements/typedefs-1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/underlying_type/requirements/typedefs-2.cc [new file with mode: 0644]

index 9d767f5beeffb4565c17d957fce3319f0c182a80..9f39823f149f6be8138e9e25a08f3fe1fd2102c0 100644 (file)
@@ -1,3 +1,14 @@
+2011-04-25  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * 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  <paolo.carlini@oracle.com>
 
        * include/parallel/multiway_merge.h: Uglify equally_split
index 11f1b0122612837b44b4cb75514d2401fdd3f4ec..6d33416c330fdb065dce12a799748d786dd92553 100644 (file)
@@ -1581,7 +1581,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
         common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
     };
 
-  /// underlying_type (still unimplemented)
+  /// underlying_type
+  template<typename _Tp>
+    struct underlying_type
+    {
+      typedef __underlying_type(_Tp) type;
+    };
 
   /// declval
   template<typename _Tp>
index debff581af5c592e475078c170ad63a362f4950b..af1522b7a40ac13a082cf3a10e93e8227c997a59 100644 (file)
@@ -19,7 +19,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "static assertion failed" "" { target *-*-* } 1598 }
+// { dg-error "static assertion failed" "" { target *-*-* } 1603 }
 
 #include <utility>
 
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 (file)
index 0000000..159e9bd
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+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<test_type1>;
+  template struct underlying_type<test_type2>;
+  template struct underlying_type<test_type3>;
+  template struct underlying_type<test_type4>;
+  template struct underlying_type<test_type5>;
+  template struct underlying_type<test_type6>;
+}
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 (file)
index 0000000..777a646
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// 
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+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<test_type1>::type  type1;
+  typedef std::underlying_type<test_type2>::type  type2;
+  typedef std::underlying_type<test_type3>::type  type3;
+  typedef std::underlying_type<test_type4>::type  type4;
+  typedef std::underlying_type<test_type5>::type  type5;
+  typedef std::underlying_type<test_type6>::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 (file)
index 0000000..b204a4f
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// 
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+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<underlying_type<E1>::type, unsigned>::value, "Error");
+  static_assert(is_same<underlying_type<E2>::type, char>::value, "Error");
+  static_assert(is_same<underlying_type<E3>::type, int>::value, "Error");
+  static_assert(is_same<underlying_type<E4>::type,
+                       unsigned char>::value, "Error");
+  static_assert(is_same<underlying_type<E5>::type, int>::value, "Error");
+  static_assert(is_same<underlying_type<E6>::type, long>::value, "Error");
+}