aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2009-11-13 02:25:12 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2009-11-13 02:25:12 +0000
commit7274deff738213914a31413a9d1a671020694175 (patch)
treefeccd24f8c12bde0673ee5c001cb4b0caeed0c30 /libstdc++-v3
parent3791ce90f6b9262cf9c52b57303cb3e8c854e328 (diff)
downloadgcc-7274deff738213914a31413a9d1a671020694175.zip
gcc-7274deff738213914a31413a9d1a671020694175.tar.gz
gcc-7274deff738213914a31413a9d1a671020694175.tar.bz2
type_traits (declval): Add, per DR 1255.
2009-11-12 Paolo Carlini <paolo.carlini@oracle.com> * include/std/type_traits (declval): Add, per DR 1255. (__is_convertible_helper, common_type): Use it. * include/bits/move.h: Mention std::declval. * testsuite/20_util/declval/requirements/1.cc: New. * testsuite/20_util/declval/requirements/1_neg.cc: Likewise. * testsuite/20_util/common_type/requirements/typedefs-2.cc: Likewise. * testsuite/20_util/common_type/requirements/ explicit_instantiation.cc: Extend. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust dg-error line numbers. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. From-SVN: r154140
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog15
-rw-r--r--libstdc++-v3/include/bits/move.h4
-rw-r--r--libstdc++-v3/include/std/type_traits45
-rw-r--r--libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc8
-rw-r--r--libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-2.cc72
-rw-r--r--libstdc++-v3/testsuite/20_util/declval/requirements/1.cc49
-rw-r--r--libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc31
-rw-r--r--libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc4
-rw-r--r--libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc4
9 files changed, 205 insertions, 27 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 9357038..4bd07dd 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,20 @@
2009-11-12 Paolo Carlini <paolo.carlini@oracle.com>
+ * include/std/type_traits (declval): Add, per DR 1255.
+ (__is_convertible_helper, common_type): Use it.
+ * include/bits/move.h: Mention std::declval.
+ * testsuite/20_util/declval/requirements/1.cc: New.
+ * testsuite/20_util/declval/requirements/1_neg.cc: Likewise.
+ * testsuite/20_util/common_type/requirements/typedefs-2.cc: Likewise.
+ * testsuite/20_util/common_type/requirements/
+ explicit_instantiation.cc: Extend.
+ * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust
+ dg-error line numbers.
+ * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
+ Likewise.
+
+2009-11-12 Paolo Carlini <paolo.carlini@oracle.com>
+
* include/bits/stl_algobase.h: Include the full <utility>, per
UK-300.
* include/bits/stl_algo.h: Tweak includes.
diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h
index 668e64c..9175481 100644
--- a/libstdc++-v3/include/bits/move.h
+++ b/libstdc++-v3/include/bits/move.h
@@ -35,7 +35,7 @@
#include <bits/concept_check.h>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
-#include <type_traits>
+#include <type_traits> // Brings in std::declval too.
_GLIBCXX_BEGIN_NAMESPACE(std)
@@ -81,6 +81,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
move(_Tp&& __t)
{ return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
+ /// declval, defined in <type_traits>.
+
_GLIBCXX_END_NAMESPACE
#define _GLIBCXX_MOVE(_Tp) std::move(_Tp)
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 788edf6..dcfa1c9 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -240,6 +240,9 @@ namespace std
: public integral_constant<bool, __is_base_of(_Base, _Derived)>
{ };
+ template<typename _Tp>
+ typename add_rvalue_reference<_Tp>::type declval();
+
// Relationships between types.
template<typename _From, typename _To,
bool = (is_void<_From>::value || is_void<_To>::value
@@ -255,10 +258,9 @@ namespace std
private:
static __one __test(_To);
static __two __test(...);
- static typename add_rvalue_reference<_From>::type __makeFrom();
public:
- static const bool __value = sizeof(__test(__makeFrom())) == 1;
+ static const bool __value = sizeof(__test(declval<_From>())) == 1;
};
// XXX FIXME
@@ -556,23 +558,11 @@ namespace std
template<typename _Tp>
struct common_type<_Tp>
- {
- static_assert(sizeof(_Tp) > 0, "must be complete type");
- typedef _Tp type;
- };
+ { typedef _Tp type; };
template<typename _Tp, typename _Up>
- class common_type<_Tp, _Up>
- {
- static_assert(sizeof(_Tp) > 0, "must be complete type");
- static_assert(sizeof(_Up) > 0, "must be complete type");
-
- static _Tp&& __t();
- static _Up&& __u();
-
- public:
- typedef decltype(true ? __t() : __u()) type;
- };
+ struct common_type<_Tp, _Up>
+ { typedef decltype(true ? declval<_Tp>() : declval<_Up>()) type; };
template<typename _Tp, typename _Up, typename... _Vp>
struct common_type<_Tp, _Up, _Vp...>
@@ -580,11 +570,26 @@ namespace std
typedef typename
common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
};
-
// @} group metaprogramming
+
+ /// declval
+ template<typename _Tp>
+ struct __declval_protector
+ {
+ static const bool __stop = false;
+ static typename add_rvalue_reference<_Tp>::type __delegate();
+ };
+
+ template<typename _Tp>
+ inline typename add_rvalue_reference<_Tp>::type
+ declval()
+ {
+ static_assert(__declval_protector<_Tp>::__stop,
+ "declval() must not be used!");
+ return __declval_protector<_Tp>::__delegate();
+ }
}
#endif // __GXX_EXPERIMENTAL_CXX0X__
-#endif // _GLIBCXX_TYPE_TRAITS
-
+#endif // _GLIBCXX_TYPE_TRAITS
diff --git a/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc
index 6d5ef30..93422ca 100644
--- a/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc
+++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc
@@ -18,7 +18,6 @@
// 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>
@@ -29,9 +28,14 @@ namespace std
typedef int& test_type2;
typedef double test_type3;
typedef float test_type4;
-
+ typedef void test_type5;
+ typedef const void test_type6;
+
template struct common_type<test_type1>;
template struct common_type<test_type1, test_type2>;
template struct common_type<test_type1, test_type2, test_type3>;
template struct common_type<test_type1, test_type2, test_type3, test_type4>;
+
+ template struct common_type<test_type5>;
+ template struct common_type<test_type5, test_type6>;
}
diff --git a/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-2.cc
new file mode 100644
index 0000000..b4a96e5
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-2.cc
@@ -0,0 +1,72 @@
+// { dg-options "-std=gnu++0x" }
+// 2009-11-12 Paolo Carlini <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2009 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/>.
+
+#include <type_traits>
+#include <testsuite_hooks.h>
+
+// DR 1255.
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::common_type;
+ using std::is_same;
+
+ VERIFY( (is_same<common_type<void>::type, void>::value) );
+ VERIFY( (is_same<common_type<const void>::type, const void>::value) );
+ VERIFY( (is_same<common_type<volatile void>::type, volatile void>::value) );
+ VERIFY( (is_same<common_type<const volatile void>::type,
+ const volatile void>::value) );
+
+ VERIFY( (is_same<common_type<void, void>::type, void>::value) );
+ VERIFY( (is_same<common_type<void, const void>::type, void>::value) );
+ VERIFY( (is_same<common_type<void, volatile void>::type, void>::value) );
+ VERIFY( (is_same<common_type<void, const volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const void, void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const void, const void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const void, volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const void, const volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<volatile void, void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<volatile void, volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<volatile void, const void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<volatile void, const volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const volatile void, void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const volatile void, const void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const volatile void, volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const volatile void, const volatile void>::type,
+ void>::value) );
+ }
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/declval/requirements/1.cc b/libstdc++-v3/testsuite/20_util/declval/requirements/1.cc
new file mode 100644
index 0000000..204d4eb
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1.cc
@@ -0,0 +1,49 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+// 2009-11-12 Paolo Carlini <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2009 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/>.
+
+#include <utility>
+
+template<typename From, typename To>
+ struct is_convertible_mini
+ {
+ private:
+ typedef char one;
+ typedef struct { char arr[2]; } two;
+
+ static one test(To);
+ static two test(...);
+
+ public:
+ static const bool value = sizeof(test(std::declval<From>())) == 1;
+};
+
+template<typename From, typename To>
+ const bool is_convertible_mini<From, To>::value;
+
+void test01()
+{
+ static_assert(is_convertible_mini<int*, const int*>::value, "#1");
+ static_assert(!is_convertible_mini<const void*, void*>::value, "#2");
+ static_assert(is_convertible_mini<float, double>::value, "#3");
+ static_assert(!is_convertible_mini<bool, int*>::value, "#4");
+ static_assert(is_convertible_mini<int(&)(int), int(*)(int)>::value, "#5");
+ static_assert(!is_convertible_mini<void*, int*>::value, "#6");
+}
diff --git a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc
new file mode 100644
index 0000000..d22a58b
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc
@@ -0,0 +1,31 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+// 2009-11-12 Paolo Carlini <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2009 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/>.
+
+// { dg-error "static assertion failed" "" { target *-*-* } 587 }
+// { dg-error "instantiated from here" "" { target *-*-* } 30 }
+// { dg-excess-errors "In function" }
+
+#include <utility>
+
+void test01()
+{
+ std::declval<int>();
+}
diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
index 2ae3754..65fc2ce 100644
--- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
@@ -48,8 +48,8 @@ void test01()
// { dg-error "instantiated from here" "" { target *-*-* } 40 }
// { dg-error "instantiated from here" "" { target *-*-* } 42 }
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 547 }
-// { dg-error "declaration of" "" { target *-*-* } 509 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 549 }
+// { dg-error "declaration of" "" { target *-*-* } 511 }
// { dg-excess-errors "At global scope" }
// { dg-excess-errors "In instantiation of" }
diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
index 5bf030c..795755f 100644
--- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
@@ -48,8 +48,8 @@ void test01()
// { dg-error "instantiated from here" "" { target *-*-* } 40 }
// { dg-error "instantiated from here" "" { target *-*-* } 42 }
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 468 }
-// { dg-error "declaration of" "" { target *-*-* } 430 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 470 }
+// { dg-error "declaration of" "" { target *-*-* } 432 }
// { dg-excess-errors "At global scope" }
// { dg-excess-errors "In instantiation of" }