diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-30 16:31:17 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-30 16:31:17 +0000 |
commit | 82d002412200dec81a72d2cb2354539d407aa715 (patch) | |
tree | c89a0f8f7618adc87a58aed670bc36f999248aaa /libstdc++-v3/testsuite/20_util | |
parent | f7e59ca4b25dcdb036be78fb4935dbbb96321835 (diff) | |
download | gcc-82d002412200dec81a72d2cb2354539d407aa715.tar.gz |
2011-05-30 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/std/tuple: Implement uses-allocator construction.
* include/bits/allocator.h (uses_allocator): Move to ...
* include/bits/uses_allocator.h: New file.
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* testsuite/20_util/uses_allocator/cons_neg.cc: New.
* testsuite/20_util/uses_allocator/construction.cc: New.
* testsuite/20_util/tuple/cons/allocate_noncopyable.cc: New.
* testsuite/20_util/tuple/cons/allocators.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@174443 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/20_util')
4 files changed, 398 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/allocate_noncopyable.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/allocate_noncopyable.cc new file mode 100644 index 00000000000..d729178b609 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/allocate_noncopyable.cc @@ -0,0 +1,73 @@ +// { 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/>. + +// 20.4.2.1 [tuple.cnstr] Allocator-extended constructors + +#include <memory> +#include <tuple> + +struct MyAlloc { }; + +struct Tag0 { }; +struct Tag1 { }; +struct Tag2 { }; + +// A non-copyable and non-movable type +struct Type +{ + typedef MyAlloc allocator_type; + + explicit Type(Tag0) { } + Type(std::allocator_arg_t, MyAlloc, Tag1) { } + Type(Tag2, MyAlloc) { } + + Type(const Type&) = delete; + Type(Type&&) = delete; + Type& operator=(const Type&) = delete; + Type& operator=(Type&&) = delete; +}; + +void test01() +{ + using std::allocator_arg; + using std::tuple; + + MyAlloc a; + Tag0 tag0; + Tag1 tag1; + Tag2 tag2; + + // N.B. cannot use Tag0 with uses-allocator construction, because + // uses_allocator<Type, MyAlloc> is true but no suitable cosntructor + tuple<Type> t1(tag0); + + tuple<Type> t2(allocator_arg, a, tag1); + tuple<Type> t3(allocator_arg, a, tag2); + + tuple<Type, Type> t4(allocator_arg, a, tag1, tag2); + + tuple<Type, Type, Type> t5(allocator_arg, a, tag2, tag1, tag2); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc new file mode 100644 index 00000000000..ae9dc8d7be2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc @@ -0,0 +1,169 @@ +// { dg-options "-std=gnu++0x" } + +// 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/>. + +// 20.4.2.1 [tuple.cnstr] Allocator-extended constructors + +#include <memory> +#include <tuple> +#include <testsuite_hooks.h> + +struct MyAlloc { }; + +// type that can't be constructed with an allocator +struct CannotUse +{ + CannotUse(int = 0, int = 0) : ok(true) { } + + bool ok; +}; + +// type that can be constructed with an allocator +// but which has uses_allocator == false +struct DoesNotUse +{ + typedef MyAlloc allocator_type; + + DoesNotUse(int = 0) : ok(true) { } + DoesNotUse(std::allocator_arg_t, MyAlloc, int = 0) : ok(false) { } + DoesNotUse(MyAlloc) : ok(false) { } + DoesNotUse(int, MyAlloc) : ok(false) { } + + DoesNotUse(const DoesNotUse&) : ok(true) { } + DoesNotUse(std::allocator_arg_t, MyAlloc, const DoesNotUse&) : ok(false) { } + DoesNotUse(const DoesNotUse&, MyAlloc) : ok(false) { } + + DoesNotUse(DoesNotUse&&) : ok(true) { } + DoesNotUse(std::allocator_arg_t, MyAlloc, DoesNotUse&&) : ok(false) { } + DoesNotUse(DoesNotUse&&, MyAlloc) : ok(false) { } + + bool ok; +}; + +namespace std +{ + template<typename A> + struct uses_allocator<DoesNotUse, A> : false_type { }; +} + +// type that can be constructed with an allocator as second argument +struct UsesWithTag +{ + typedef MyAlloc allocator_type; + + UsesWithTag(int = 0) : ok(false) { } + UsesWithTag(std::allocator_arg_t, MyAlloc, int = 0) : ok(true) { } + UsesWithTag(MyAlloc) : ok(false) { } + UsesWithTag(int, MyAlloc) : ok(false) { } + + UsesWithTag(const UsesWithTag&) : ok(false) { } + UsesWithTag(std::allocator_arg_t, MyAlloc, const UsesWithTag&) : ok(true) { } + UsesWithTag(const UsesWithTag&, MyAlloc) : ok(false) { } + + UsesWithTag(UsesWithTag&&) : ok(false) { } + UsesWithTag(std::allocator_arg_t, MyAlloc, UsesWithTag&&) : ok(true) { } + UsesWithTag(UsesWithTag&&, MyAlloc) : ok(false) { } + + bool ok; +}; + +// type that can be constructed with an allocator as last argument +struct UsesWithoutTag +{ + typedef MyAlloc allocator_type; + + UsesWithoutTag(int = 0) : ok(false) { } + UsesWithoutTag(MyAlloc) : ok(true) { } + UsesWithoutTag(int, MyAlloc) : ok(true) { } + + UsesWithoutTag(const UsesWithoutTag&) : ok(false) { } + UsesWithoutTag(const UsesWithoutTag&, MyAlloc) : ok(true) { } + + UsesWithoutTag(UsesWithoutTag&&) : ok(false) { } + UsesWithoutTag(UsesWithoutTag&&, MyAlloc) : ok(true) { } + + bool ok; +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::allocator_arg; + using std::tuple; + using std::make_tuple; + using std::get; + + typedef CannotUse T1; + typedef DoesNotUse T2; + typedef UsesWithTag T3; + typedef UsesWithoutTag T4; + typedef tuple<T1, T2, T3, T4> test_type; + + MyAlloc a; + + // default construction + test_type t1(allocator_arg, a); + VERIFY( get<0>(t1).ok ); + VERIFY( get<1>(t1).ok ); + VERIFY( get<2>(t1).ok ); + VERIFY( get<3>(t1).ok ); + + // copy construction + test_type t2(allocator_arg, a, t1); + VERIFY( get<0>(t2).ok ); + VERIFY( get<1>(t2).ok ); + VERIFY( get<2>(t2).ok ); + VERIFY( get<3>(t2).ok ); + + // move construction + test_type t3(allocator_arg, a, std::move(t1)); + VERIFY( get<0>(t3).ok ); + VERIFY( get<1>(t3).ok ); + VERIFY( get<2>(t3).ok ); + VERIFY( get<3>(t3).ok ); + + // construction from int + test_type t4(allocator_arg, a, 1, 2, 3, 4); + VERIFY( get<0>(t4).ok ); + VERIFY( get<1>(t4).ok ); + VERIFY( get<2>(t4).ok ); + VERIFY( get<3>(t4).ok ); + + auto ints = make_tuple(1, 2, 3, 4); + + // construction from lvalue tuple of ints + test_type t5(allocator_arg, a, ints); + VERIFY( get<0>(t5).ok ); + VERIFY( get<1>(t5).ok ); + VERIFY( get<2>(t5).ok ); + VERIFY( get<3>(t2).ok ); + + // construction from rvalue tuple of ints + test_type t6(allocator_arg, a, std::move(ints)); + VERIFY( get<0>(t6).ok ); + VERIFY( get<1>(t6).ok ); + VERIFY( get<2>(t6).ok ); + VERIFY( get<3>(t6).ok ); + +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/cons_neg.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/cons_neg.cc new file mode 100644 index 00000000000..b6b706c67eb --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/cons_neg.cc @@ -0,0 +1,48 @@ +// { 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/>. + +// 20.4.2.1 [tuple.cnstr] Allocator-extended constructors + +#include <memory> +#include <tuple> + +struct MyAlloc { }; + +struct Type +{ + typedef MyAlloc allocator_type; // uses_allocator<Type, MyAlloc> is true + + explicit Type(int) { } + + Type(std::allocator_arg_t, MyAlloc) { } + Type(MyAlloc) { } +}; + +void test01() +{ + using std::allocator_arg; + using std::tuple; + + MyAlloc a; + + tuple<Type> t(allocator_arg, a, 1); +} +// { dg-error "no matching function" "" { target *-*-* } 112 } +// { dg-excess-errors "note" } diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/construction.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/construction.cc new file mode 100644 index 00000000000..94fca79c252 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/construction.cc @@ -0,0 +1,108 @@ +// { dg-options "-std=gnu++0x" } + +// 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/>. + +// 20.6.7.2 uses-allocator construction + +#include <memory> +#include <tuple> +#include <testsuite_hooks.h> + +struct MyAlloc { }; + +// type that can't be constructed with an allocator +struct CannotUse +{ + CannotUse(int) : ok(true) { } + + bool ok; +}; + +// type that can be constructed with an allocator +// but which has uses_allocator == false +struct DoesNotUse +{ + typedef MyAlloc allocator_type; + + DoesNotUse(int) : ok(true) { } + DoesNotUse(std::allocator_arg_t, MyAlloc, int) : ok(false) { } + DoesNotUse(int, MyAlloc) : ok(false) { } + + bool ok; +}; + +namespace std +{ + template<typename A> + struct uses_allocator<DoesNotUse, A> : false_type { }; +} + +// type that can be constructed with an allocator as second argument +struct UsesWithTag +{ + typedef MyAlloc allocator_type; + + UsesWithTag(int) : ok(false) { } + UsesWithTag(std::allocator_arg_t, MyAlloc, int) : ok(true) { } + UsesWithTag(int, MyAlloc) : ok(false) { } + + bool ok; +}; + +// type that can be constructed with an allocator as last argument +struct UsesWithoutTag +{ + typedef MyAlloc allocator_type; + + UsesWithoutTag(int) : ok(false) { } + UsesWithoutTag(int, MyAlloc) : ok(true) { } + + bool ok; +}; + + +template<typename TestType, typename... T> + bool test2(T... args) + { + using std::allocator_arg; + using std::tuple; + using std::get; + + tuple<TestType, T...> t(allocator_arg, MyAlloc(), 1, args...); + + return get<0>(t).ok; + } + +template<typename... T> + void test(T... args) + { + bool test __attribute__((unused)) = true; + + VERIFY( test2<CannotUse>(args...) ); + VERIFY( test2<DoesNotUse>(args...) ); + VERIFY( test2<UsesWithTag>(args...) ); + VERIFY( test2<UsesWithoutTag>(args...) ); + } + +int main() +{ + test(); + test(1); + test(1, 2); + return 0; +} |