aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2010-09-27 17:27:43 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2010-09-27 17:27:43 +0000
commitaa2b7414b0ec4a1c18998561b4aedd3abbf09dbf (patch)
treee814b2297b9bdbc7c65042472861e403c24dfb16 /libstdc++-v3
parentfa2ea33de80cd95b2a1d1a759b2271cb8d7e32db (diff)
downloadgcc-aa2b7414b0ec4a1c18998561b4aedd3abbf09dbf.zip
gcc-aa2b7414b0ec4a1c18998561b4aedd3abbf09dbf.tar.gz
gcc-aa2b7414b0ec4a1c18998561b4aedd3abbf09dbf.tar.bz2
allocator.h (allocator_arg_t, [...]): Add.
2010-09-27 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/allocator.h (allocator_arg_t, allocator_arg, uses_allocator): Add. * testsuite/20_util/uses_allocator/value.cc: New. * testsuite/20_util/uses_allocator/requirements/typedefs.cc: Likewise. * testsuite/20_util/uses_allocator/requirements/ explicit_instantiation.cc: Likewise. * include/bits/stl_queue.h (uses_allocator<queue>, uses_allocator<priority_queue>): Add. * include/bits/stl_stack.h (uses_allocator<stack>): Likewise. * include/bits/stl_pair.h (piecewise_construct): Add. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error line number. From-SVN: r164654
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog16
-rw-r--r--libstdc++-v3/include/bits/allocator.h91
-rw-r--r--libstdc++-v3/include/bits/stl_pair.h3
-rw-r--r--libstdc++-v3/include/bits/stl_queue.h9
-rw-r--r--libstdc++-v3/include/bits/stl_stack.h4
-rw-r--r--libstdc++-v3/testsuite/20_util/uses_allocator/requirements/explicit_instantiation.cc29
-rw-r--r--libstdc++-v3/testsuite/20_util/uses_allocator/requirements/typedefs.cc33
-rw-r--r--libstdc++-v3/testsuite/20_util/uses_allocator/value.cc59
-rw-r--r--libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc2
9 files changed, 223 insertions, 23 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 42ea0b3..23908a2 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,21 @@
2010-09-27 Paolo Carlini <paolo.carlini@oracle.com>
+ * include/bits/allocator.h (allocator_arg_t, allocator_arg,
+ uses_allocator): Add.
+ * testsuite/20_util/uses_allocator/value.cc: New.
+ * testsuite/20_util/uses_allocator/requirements/typedefs.cc: Likewise.
+ * testsuite/20_util/uses_allocator/requirements/
+ explicit_instantiation.cc: Likewise.
+ * include/bits/stl_queue.h (uses_allocator<queue>,
+ uses_allocator<priority_queue>): Add.
+ * include/bits/stl_stack.h (uses_allocator<stack>): Likewise.
+
+ * include/bits/stl_pair.h (piecewise_construct): Add.
+ * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error
+ line number.
+
+2010-09-27 Paolo Carlini <paolo.carlini@oracle.com>
+
* include/c_std/cmath (__pow_helper): Remove.
(__cmath_power): Remove declaration.
* include/c_global/cmath: Likewise.
diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h
index ddf48db..2d7a4e1 100644
--- a/libstdc++-v3/include/bits/allocator.h
+++ b/libstdc++-v3/include/bits/allocator.h
@@ -47,6 +47,10 @@
// Define the base class to std::allocator.
#include <bits/c++allocator.h>
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#include <type_traits>
+#endif
+
_GLIBCXX_BEGIN_NAMESPACE(std)
/**
@@ -177,28 +181,71 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
};
#ifdef __GXX_EXPERIMENTAL_CXX0X__
- // A very basic implementation for now. In general we have to wait for
- // the availability of the infrastructure described in N2983: we should
- // try when either T has a move constructor which cannot throw or T is
- // CopyContructible.
- // NB: This code doesn't properly belong here, we should find a more
- // suited place common to std::vector and std::deque.
- template<typename _Tp,
- bool = __has_trivial_copy(typename _Tp::value_type)>
- struct __shrink_to_fit
- { static void _S_do_it(_Tp&) { } };
-
- template<typename _Tp>
- struct __shrink_to_fit<_Tp, true>
- {
- static void
- _S_do_it(_Tp& __v)
- {
- __try
- { _Tp(__v).swap(__v); }
- __catch(...) { }
- }
- };
+ // A very basic implementation for now. In general we have to wait for
+ // the availability of the infrastructure described in N2983: we should
+ // try when either T has a move constructor which cannot throw or T is
+ // CopyContructible.
+ // NB: This code doesn't properly belong here, we should find a more
+ // suited place common to std::vector and std::deque.
+ template<typename _Tp,
+ bool = __has_trivial_copy(typename _Tp::value_type)>
+ struct __shrink_to_fit
+ { static void _S_do_it(_Tp&) { } };
+
+ template<typename _Tp>
+ struct __shrink_to_fit<_Tp, true>
+ {
+ static void
+ _S_do_it(_Tp& __v)
+ {
+ __try
+ { _Tp(__v).swap(__v); }
+ __catch(...) { }
+ }
+ };
+
+
+ /// [allocator.tag]
+ struct allocator_arg_t { };
+
+ static const allocator_arg_t allocator_arg = allocator_arg_t();
+
+ template<typename _Tp>
+ class __has_allocator_type
+ : public __sfinae_types
+ {
+ template<typename _Up>
+ struct _Wrap_type
+ { };
+
+ template<typename _Up>
+ static __one __test(_Wrap_type<typename _Up::allocator_type>*);
+
+ template<typename _Up>
+ static __two __test(...);
+
+ public:
+ static const bool __value = sizeof(__test<_Tp>(0)) == 1;
+ };
+
+ template<typename _Tp, typename _Alloc,
+ bool = __has_allocator_type<_Tp>::__value>
+ struct __uses_allocator_helper
+ : public false_type { };
+
+ template<typename _Tp, typename _Alloc>
+ struct __uses_allocator_helper<_Tp, _Alloc, true>
+ : public integral_constant<bool, is_convertible<_Alloc,
+ typename _Tp::allocator_type>::value>
+ { };
+
+ /// [allocator.uses.trait]
+ template<typename _Tp, typename _Alloc>
+ struct uses_allocator
+ : public integral_constant<bool,
+ __uses_allocator_helper<_Tp, _Alloc>::value>
+ { };
+
#endif
_GLIBCXX_END_NAMESPACE
diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h
index c5f2986..f4b339d 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -68,6 +68,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
#ifdef __GXX_EXPERIMENTAL_CXX0X__
struct piecewise_construct_t { };
+ static const piecewise_construct_t piecewise_construct
+ = piecewise_construct_t();
+
// forward declarations
template<typename...>
class tuple;
diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h
index 96e29ed..85a06ab 100644
--- a/libstdc++-v3/include/bits/stl_queue.h
+++ b/libstdc++-v3/include/bits/stl_queue.h
@@ -307,6 +307,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
inline void
swap(queue<_Tp, _Seq>& __x, queue<_Tp, _Seq>& __y)
{ __x.swap(__y); }
+
+ template<typename _Tp, typename _Seq, typename _Alloc>
+ struct uses_allocator<queue<_Tp, _Seq>, _Alloc>
+ : public uses_allocator<_Seq, _Alloc>::type { };
#endif
/**
@@ -536,6 +540,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
priority_queue<_Tp, _Sequence, _Compare>& __y)
{ __x.swap(__y); }
+
+ template<typename _Tp, typename _Sequence, typename _Compare,
+ typename _Alloc>
+ struct uses_allocator<priority_queue<_Tp, _Sequence, _Compare>, _Alloc>
+ : public uses_allocator<_Sequence, _Alloc>::type { };
#endif
_GLIBCXX_END_NAMESPACE
diff --git a/libstdc++-v3/include/bits/stl_stack.h b/libstdc++-v3/include/bits/stl_stack.h
index 26f50ad..7312a35 100644
--- a/libstdc++-v3/include/bits/stl_stack.h
+++ b/libstdc++-v3/include/bits/stl_stack.h
@@ -282,6 +282,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
inline void
swap(stack<_Tp, _Seq>& __x, stack<_Tp, _Seq>& __y)
{ __x.swap(__y); }
+
+ template<typename _Tp, typename _Seq, typename _Alloc>
+ struct uses_allocator<stack<_Tp, _Seq>, _Alloc>
+ : public uses_allocator<_Seq, _Alloc>::type { };
#endif
_GLIBCXX_END_NAMESPACE
diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/requirements/explicit_instantiation.cc
new file mode 100644
index 0000000..5a43088
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/uses_allocator/requirements/explicit_instantiation.cc
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// 2010-09-27 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 <memory>
+
+namespace std
+{
+ typedef short test_type;
+ template struct uses_allocator<test_type, test_type>;
+}
diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/requirements/typedefs.cc
new file mode 100644
index 0000000..fad654d
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/uses_allocator/requirements/typedefs.cc
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// 2010-09-27 Paolo Carlini <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2010 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 <memory>
+
+void test01()
+{
+ // Check for required typedefs
+ typedef std::uses_allocator<int, int> test_type;
+ typedef test_type::value_type value_type;
+ typedef test_type::type type;
+ typedef test_type::type::value_type type_value_type;
+ typedef test_type::type::type type_type;
+}
diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/value.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/value.cc
new file mode 100644
index 0000000..5a7b0a8
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/uses_allocator/value.cc
@@ -0,0 +1,59 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2010-09-27 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 <memory>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+struct MyAlloc { };
+
+struct MyDerivedAlloc
+: public MyAlloc { };
+
+struct UA { };
+
+struct UB { typedef int allocator_type; };
+
+struct UC { typedef MyAlloc allocator_type; };
+
+struct UD { typedef MyDerivedAlloc allocator_type; };
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::uses_allocator;
+ using namespace __gnu_test;
+
+ // Positive tests.
+ VERIFY( (test_relationship<uses_allocator, UC, MyAlloc>(true)) );
+ VERIFY( (test_relationship<uses_allocator, UC, MyDerivedAlloc>(true)));
+
+ // Negative tests.
+ VERIFY( (test_relationship<uses_allocator, UA, MyAlloc>(false)) );
+ VERIFY( (test_relationship<uses_allocator, UB, MyAlloc>(false)) );
+ VERIFY( (test_relationship<uses_allocator, UD, MyAlloc>(false)) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc
index f124718..fbb24c0 100644
--- a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc
@@ -48,4 +48,4 @@ main()
// { dg-warning "note" "" { target *-*-* } 1027 }
// { dg-warning "note" "" { target *-*-* } 340 }
// { dg-warning "note" "" { target *-*-* } 290 }
-// { dg-warning "note" "" { target *-*-* } 197 }
+// { dg-warning "note" "" { target *-*-* } 200 }