diff options
Diffstat (limited to 'libstdc++-v3/testsuite/20_util')
382 files changed, 20922 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/add_lvalue_reference/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/add_lvalue_reference/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..aa1dc3759 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/add_lvalue_reference/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct add_lvalue_reference<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/add_lvalue_reference/value.cc b/libstdc++-v3/testsuite/20_util/add_lvalue_reference/value.cc new file mode 100644 index 000000000..189f4457b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/add_lvalue_reference/value.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::add_lvalue_reference; + using std::is_same; + using namespace __gnu_test; + + VERIFY( (is_same<add_lvalue_reference<int>::type, int&>::value) ); + VERIFY( (is_same<add_lvalue_reference<int&>::type, int&>::value) ); + VERIFY( (is_same<add_lvalue_reference<const int>::type, const int&>::value) ); + VERIFY( (is_same<add_lvalue_reference<int*>::type, int*&>::value) ); + VERIFY( (is_same<add_lvalue_reference<ClassType&>::type, ClassType&>::value) ); + VERIFY( (is_same<add_lvalue_reference<ClassType>::type, ClassType&>::value) ); + VERIFY( (is_same<add_lvalue_reference<int(int)>::type, int(&)(int)>::value) ); + VERIFY( (is_same<add_lvalue_reference<int&&>::type, int&>::value) ); + VERIFY( (is_same<add_lvalue_reference<ClassType&&>::type, ClassType&>::value) ); + VERIFY( (is_same<add_lvalue_reference<void>::type, void>::value) ); + VERIFY( (is_same<add_lvalue_reference<const void>::type, const void>::value) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/add_rvalue_reference/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/add_rvalue_reference/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..c99902816 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/add_rvalue_reference/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct add_rvalue_reference<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/add_rvalue_reference/value.cc b/libstdc++-v3/testsuite/20_util/add_rvalue_reference/value.cc new file mode 100644 index 000000000..397178cfe --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/add_rvalue_reference/value.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::add_rvalue_reference; + using std::is_same; + using namespace __gnu_test; + + VERIFY( (is_same<add_rvalue_reference<int>::type, int&&>::value) ); + VERIFY( (is_same<add_rvalue_reference<int&&>::type, int&&>::value) ); + VERIFY( (is_same<add_rvalue_reference<const int>::type, const int&&>::value) ); + VERIFY( (is_same<add_rvalue_reference<int*>::type, int*&&>::value) ); + VERIFY( (is_same<add_rvalue_reference<ClassType&&>::type, ClassType&&>::value) ); + VERIFY( (is_same<add_rvalue_reference<ClassType>::type, ClassType&&>::value) ); + VERIFY( (is_same<add_rvalue_reference<int(int)>::type, int(&&)(int)>::value) ); + VERIFY( (is_same<add_rvalue_reference<void>::type, void>::value) ); + VERIFY( (is_same<add_rvalue_reference<const void>::type, const void>::value) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/addressof/1.cc b/libstdc++-v3/testsuite/20_util/addressof/1.cc new file mode 100644 index 000000000..43009f3c8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/addressof/1.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-05-20 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_api.h> + +void f1(int) { } + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + OverloadedAddress* ao1 = new OverloadedAddress(); + OverloadedAddress& o1 = *ao1; + + VERIFY( std::addressof(o1) == ao1 ); + + const OverloadedAddress* ao2 = new OverloadedAddress(); + const OverloadedAddress& o2 = *ao2; + + VERIFY( std::addressof(o2) == ao2 ); + + VERIFY( std::addressof(f1) == &f1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/addressof/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/addressof/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..559cd20e2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/addressof/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-05-20 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/>. + +// NB: This file is for testing utility with NO OTHER INCLUDES. + +#include <memory> + +namespace std +{ + typedef short test_type; + template short* addressof(short&); +} diff --git a/libstdc++-v3/testsuite/20_util/aligned_storage/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/aligned_storage/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..6186d8e8a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/aligned_storage/requirements/explicit_instantiation.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-09-17 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct aligned_storage<1, alignment_of<test_type>::value>; + template struct aligned_storage<2>; +} diff --git a/libstdc++-v3/testsuite/20_util/aligned_storage/value.cc b/libstdc++-v3/testsuite/20_util/aligned_storage/value.cc new file mode 100644 index 000000000..1399a11a7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/aligned_storage/value.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } +// 2007-09-17 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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> +#include <testsuite_tr1.h> + +struct MSAlignType { } __attribute__((__aligned__)); + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::aligned_storage; + using std::alignment_of; + using namespace __gnu_test; + + const std::size_t align_c = alignment_of<char>::value; + VERIFY( (sizeof(aligned_storage<4, align_c>::type) >= 4) ); + VERIFY( (__alignof__(aligned_storage<4, align_c>::type) == align_c) ); + + const std::size_t align_s = alignment_of<short>::value; + VERIFY( (sizeof(aligned_storage<1, align_s>::type) >= 1) ); + VERIFY( (__alignof__(aligned_storage<1, align_s>::type) == align_s) ); + + const std::size_t align_i = alignment_of<int>::value; + VERIFY( (sizeof(aligned_storage<7, align_i>::type) >= 7) ); + VERIFY( (__alignof__(aligned_storage<7, align_i>::type) == align_i) ); + + const std::size_t align_d = alignment_of<double>::value; + VERIFY( (sizeof(aligned_storage<2, align_d>::type) >= 2) ); + VERIFY( (__alignof__(aligned_storage<2, align_d>::type) == align_d) ); + + const std::size_t align_ai = alignment_of<int[4]>::value; + VERIFY( (sizeof(aligned_storage<20, align_ai>::type) >= 20) ); + VERIFY( (__alignof__(aligned_storage<20, align_ai>::type) == align_ai) ); + + const std::size_t align_ct = alignment_of<ClassType>::value; + VERIFY( (sizeof(aligned_storage<11, align_ct>::type) >= 11) ); + VERIFY( (__alignof__(aligned_storage<11, align_ct>::type) == align_ct) ); + + const std::size_t align_msa = alignment_of<MSAlignType>::value; + VERIFY( (sizeof(aligned_storage<5>::type) >= 5) ); + VERIFY( (__alignof__(aligned_storage<5>::type) == align_msa) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/allocator/1.cc b/libstdc++-v3/testsuite/20_util/allocator/1.cc new file mode 100644 index 000000000..0e1024745 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator/1.cc @@ -0,0 +1,65 @@ +// 2001-06-14 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2004, 2005, 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/>. + +// 20.4.1.1 allocator members + +#include <memory> +#include <stdexcept> +#include <cstdlib> +#include <testsuite_hooks.h> + +struct gnu { }; + +bool check_new = false; +bool check_delete = false; + +void* +operator new(std::size_t n) throw(std::bad_alloc) +{ + check_new = true; + return std::malloc(n); +} + +void operator delete(void *v) throw() +{ + check_delete = true; + return std::free(v); +} + +void test01() +{ + bool test __attribute__((unused)) = true; + std::allocator<gnu> obj; + + // NB: These should work for various size allocation and + // deallocations. Currently, they only work as expected for sizes > + // _MAX_BYTES as defined in stl_alloc.h, which happes to be 128. + gnu* pobj = obj.allocate(256); + VERIFY( check_new ); + + obj.deallocate(pobj, 256); + VERIFY( check_delete ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/20_util/allocator/10378.cc b/libstdc++-v3/testsuite/20_util/allocator/10378.cc new file mode 100644 index 000000000..f8a7f1ad3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator/10378.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2003, 2004, 2005, 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/>. + +// 20.1.5 allocator requirements / 20.4.1.1 allocator members + +#include <list> +#include <cstdlib> +#include <testsuite_hooks.h> + +class Bob +{ +public: + static void* operator new(size_t sz) + { return std::malloc(sz); } +}; + +// libstdc++/10378 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + list<Bob> uniset; + uniset.push_back(Bob()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/allocator/14176.cc b/libstdc++-v3/testsuite/20_util/allocator/14176.cc new file mode 100644 index 000000000..c7442509d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator/14176.cc @@ -0,0 +1,36 @@ +// Copyright (C) 2004, 2005, 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/>. + +// 20.4.1.1 allocator members + +#include <memory> +#include <testsuite_hooks.h> + +// libstdc++/14176 +void test02() +{ + unsigned int len = 0; + std::allocator<int> a; + int* p = a.allocate(len); + a.deallocate(p, len); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/allocator/33807.cc b/libstdc++-v3/testsuite/20_util/allocator/33807.cc new file mode 100644 index 000000000..637bfcbae --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator/33807.cc @@ -0,0 +1,32 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <list> + +// libstdc++/33807 +template <class T> +bool operator != (const T& x, const T& y) { return !(x == y); } + +struct foo { }; + +void fnx() +{ + std::list<foo> l1, l2; + l1 = l2; +} diff --git a/libstdc++-v3/testsuite/20_util/allocator/51626.cc b/libstdc++-v3/testsuite/20_util/allocator/51626.cc new file mode 100644 index 000000000..951aa18fe --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator/51626.cc @@ -0,0 +1,66 @@ +// 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/>. + +// { dg-options "-std=gnu++0x" } + +#include <memory> +#include <vector> +#include <testsuite_hooks.h> + +int count = 0; + +template <class T> + struct allocator98 : std::allocator<T> + { + template <class U> struct rebind { typedef allocator98<U> other; }; + + allocator98() { } + + template <class U> allocator98(const allocator98<U>&) { }; + + void construct(T* p, const T& val) + { + ++count; + std::allocator<T>::construct(p, val); + } + }; + +template <class T> + struct allocator11 : std::allocator<T> + { + template <class U> struct rebind { typedef allocator11<U> other; }; + + allocator11() { } + + template <class U> allocator11(const allocator11<U>&) { }; + + template<typename... Args> + void construct(T* p, Args&&... args) + { + ++count; + std::allocator<T>::construct(p, std::forward<Args>(args)...); + } + }; + +int main() +{ + std::vector< int, allocator98<int> > v98(1); + VERIFY( count == 0 ); + + std::vector< int, allocator11<int> > v11(1); + VERIFY( count == 1 ); +} diff --git a/libstdc++-v3/testsuite/20_util/allocator/8230.cc b/libstdc++-v3/testsuite/20_util/allocator/8230.cc new file mode 100644 index 000000000..e71f51d21 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator/8230.cc @@ -0,0 +1,53 @@ +// 2001-06-14 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2004, 2005, 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/>. + +// 20.4.1.1 allocator members + +#include <memory> +#include <stdexcept> +#include <testsuite_hooks.h> + +// libstdc++/8230 +void test02() +{ + bool test __attribute__((unused)) = true; + try + { + std::allocator<int> alloc; + const std::allocator<int>::size_type n = alloc.max_size(); + int* p = alloc.allocate(n + 1); + p[n] = 2002; + } + catch(const std::bad_alloc& e) + { + // Allowed. + test = true; + } + catch(...) + { + test = false; + } + VERIFY( test ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/allocator/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/20_util/allocator/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..5ca0be4ab --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <memory> + +template class std::allocator<int>; diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/1.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/1.cc new file mode 100644 index 000000000..f5246482f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/1.cc @@ -0,0 +1,94 @@ +// Copyright (C) 2000, 2002, 2003, 2004, 2009 Free Software Foundation +// +// 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.5 Template class auto_ptr [lib.auto.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + + +// 20.4.5.1 auto_ptr constructors [lib.auto.ptr.cons] + +// Construction from pointer +int +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::auto_ptr<A> A_default; + VERIFY( A_default.get() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + std::auto_ptr<A> A_from_A(new A); + VERIFY( A_from_A.get() != 0 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + std::auto_ptr<A> A_from_B(new B); + VERIFY( A_from_B.get() != 0 ); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/2.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/2.cc new file mode 100644 index 000000000..0ae57f97e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/2.cc @@ -0,0 +1,84 @@ +// Copyright (C) 2000, 2002, 2003, 2004, 2009 Free Software Foundation +// +// 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.5 Template class auto_ptr [lib.auto.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + +// Construction from std::auto_ptr +int +test02() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::auto_ptr<A> A_from_A(new A); + std::auto_ptr<B> B_from_B(new B); + + std::auto_ptr<A> A_from_ptr_A(A_from_A); + std::auto_ptr<A> A_from_ptr_B(B_from_B); + VERIFY( A_from_A.get() == 0 ); + VERIFY( B_from_B.get() == 0 ); + VERIFY( A_from_ptr_A.get() != 0 ); + VERIFY( A_from_ptr_B.get() != 0 ); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/3.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/3.cc new file mode 100644 index 000000000..78fd5aaf6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/3.cc @@ -0,0 +1,86 @@ +// Copyright (C) 2000, 2002, 2003, 2004, 2009 Free Software Foundation +// +// 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.5 Template class auto_ptr [lib.auto.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + +// Assignment from std::auto_ptr +int +test03() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::auto_ptr<A> A_from_ptr_A; + std::auto_ptr<A> A_from_ptr_B; + std::auto_ptr<A> A_from_A(new A); + std::auto_ptr<B> B_from_B(new B); + + A_from_ptr_A = A_from_A; + A_from_ptr_B = B_from_B; + VERIFY( A_from_A.get() == 0 ); + VERIFY( B_from_B.get() == 0 ); + VERIFY( A_from_ptr_A.get() != 0 ); + VERIFY( A_from_ptr_B.get() != 0 ); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/3946.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/3946.cc new file mode 100644 index 000000000..be034c00c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/3946.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2000, 2002, 2003, 2004, 2009 Free Software Foundation +// +// 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.5 Template class auto_ptr [lib.auto.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +// libstdc++/3946 +// http://gcc.gnu.org/ml/libstdc++/2002-07/msg00024.html +struct Base { }; +struct Derived : public Base { }; + +std::auto_ptr<Derived> +conversiontest08() { return std::auto_ptr<Derived>(new Derived); } + +void +test08() +{ + std::auto_ptr<Base> ptr; + ptr = conversiontest08(); +} + + +int +main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/4.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/4.cc new file mode 100644 index 000000000..a623a87b5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/4.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2000, 2002, 2003, 2004, 2009 Free Software Foundation +// +// 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.5 Template class auto_ptr [lib.auto.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + + +// Destruction +int +test04() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + {/*lifetine scope*/ + std::auto_ptr<A> A_from_A(new A); + std::auto_ptr<A> A_from_B(new B); + std::auto_ptr<B> B_from_B(new B); + }/*destructors called here*/ + + VERIFY( A::ctor_count == 3 ); + VERIFY( A::dtor_count == 3 ); + VERIFY( B::ctor_count == 2 ); + VERIFY( B::dtor_count == 2 ); + + return 0; +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/5.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/5.cc new file mode 100644 index 000000000..2f61520e2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/5.cc @@ -0,0 +1,86 @@ +// Copyright (C) 2000, 2002, 2003, 2004, 2009 Free Software Foundation +// +// 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.5 Template class auto_ptr [lib.auto.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + + +// Class member construction/destruction +template <typename T> +class pimpl +{ +public: + pimpl() : p_impl(new T) {} +private: + std::auto_ptr<T> p_impl; +}; + +int +test05() +{ + bool test __attribute__((unused)) = true; + reset_count_struct __attribute__((unused)) reset; + + pimpl<A>(); + pimpl<B>(); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 2 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 1 ); + return 0; +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/6.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/6.cc new file mode 100644 index 000000000..88c2405f2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/6.cc @@ -0,0 +1,90 @@ +// Copyright (C) 2000, 2002, 2003, 2004, 2009 Free Software Foundation +// +// 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.5 Template class auto_ptr [lib.auto.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + +// 20.4.5.2 auto_ptr members [lib.auto.ptr.members] + +// Member access +int +test06() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::auto_ptr<A> A_from_A(new A); + std::auto_ptr<A> A_from_A_ptr(A_from_A.release()); + VERIFY( A_from_A.get() == 0 ); + VERIFY( A_from_A_ptr.get() != 0 ); + VERIFY( A_from_A_ptr->ctor_count == 1 ); + VERIFY( (*A_from_A_ptr).dtor_count == 0 ); + + A* A_ptr = A_from_A_ptr.get(); + + A_from_A_ptr.reset(A_ptr); + VERIFY( A_from_A_ptr.get() == A_ptr ); + VERIFY( A_from_A_ptr->ctor_count == 1 ); + VERIFY( (*A_from_A_ptr).dtor_count == 0 ); + + A_from_A_ptr.reset(new A); + VERIFY( A_from_A_ptr.get() != A_ptr ); + VERIFY( A_from_A_ptr->ctor_count == 2 ); + VERIFY( (*A_from_A_ptr).dtor_count == 1 ); + return 0; +} + +int +main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/7.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/7.cc new file mode 100644 index 000000000..cf7ea89bf --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/7.cc @@ -0,0 +1,90 @@ +// Copyright (C) 2000, 2002, 2003, 2004, 2009 Free Software Foundation +// +// 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.5 Template class auto_ptr [lib.auto.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + +// 20.4.5.3 auto_ptr conversions [lib.auto.ptr.conv] + +// Parameters and return values +template <typename T> +static std::auto_ptr<T> source() +{ + return std::auto_ptr<T>(new T); +} + +template <typename T> +static void drain(std::auto_ptr<T>) +{} + +int +test07() +{ + bool test __attribute__((unused)) = true; + reset_count_struct __attribute__((unused)) reset; + + drain(source<A>()); + // The resolution of core issue 84, now a DR, breaks this call. + // drain<A>(source<B>()); + drain(source<B>()); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 2 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 1 ); + return 0; +} + +int +main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/assign_neg.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/assign_neg.cc new file mode 100644 index 000000000..617d76b80 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/assign_neg.cc @@ -0,0 +1,52 @@ +// { dg-do compile } + +// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 +// Free Software Foundation +// +// 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.5 Template class auto_ptr negative tests [lib.auto.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +// via Jack Reeves <jack_reeves@hispeed.ch> +// libstdc++/3946 +// http://gcc.gnu.org/ml/libstdc++/2002-07/msg00024.html +struct Base { }; +struct Derived : public Base { }; + +std::auto_ptr<Derived> +foo() { return std::auto_ptr<Derived>(new Derived); } + +int +test01() +{ + std::auto_ptr<Base> ptr2; + ptr2 = new Base; // { dg-error "no match" } + // { dg-error "candidate" "candidate note" { target *-*-* } 39 } + return 0; +} + +int +main() +{ + test01(); + return 0; +} +// { dg-error "::auto_ptr|no known conversion" "" { target *-*-* } 136 } +// { dg-error "note" "" { target *-*-* } 154 } +// { dg-error "::auto_ptr|no known conversion" "" { target *-*-* } 264 } diff --git a/libstdc++-v3/testsuite/20_util/auto_ptr/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/20_util/auto_ptr/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..32b526bf3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/auto_ptr/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <memory> + +template class std::auto_ptr<int>; diff --git a/libstdc++-v3/testsuite/20_util/bad_function_call/cons_virtual_derivation.cc b/libstdc++-v3/testsuite/20_util/bad_function_call/cons_virtual_derivation.cc new file mode 100644 index 000000000..8ff6d981b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bad_function_call/cons_virtual_derivation.cc @@ -0,0 +1,29 @@ +// { dg-options "-std=gnu++0x" } +// 2007-05-29 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 2008, 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 <functional> +#include <testsuite_api.h> + +int main() +{ + typedef std::bad_function_call test_type; + __gnu_test::diamond_derivation<test_type, true>::test(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/35569.cc b/libstdc++-v3/testsuite/20_util/bind/35569.cc new file mode 100644 index 000000000..8d25f1a8a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/35569.cc @@ -0,0 +1,32 @@ +// 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/>. + +// 20.7.11 Function template bind + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <functional> + +using namespace std; +using namespace std::placeholders; + +void test01() +{ + bind(multiplies<int>(),4,_1)(5); +} + diff --git a/libstdc++-v3/testsuite/20_util/bind/38889.cc b/libstdc++-v3/testsuite/20_util/bind/38889.cc new file mode 100644 index 000000000..b4f47c6c4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/38889.cc @@ -0,0 +1,31 @@ +// 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/>. + +// 20.7.11 Function template bind + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <functional> + +void goo(int); +void foo() { + std::bind (goo,1)(); + std::bind (goo,std::placeholders::_1)(1); +} + + diff --git a/libstdc++-v3/testsuite/20_util/bind/42593.cc b/libstdc++-v3/testsuite/20_util/bind/42593.cc new file mode 100644 index 000000000..327d1df54 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/42593.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// 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/>. + +// 20.7.11 Function template bind + +#include <functional> + +void f( int ) {} + +void test01() +{ + std::function< void( int ) > pf = std::bind( &f, std::placeholders::_1 ); + pf(1); +} + diff --git a/libstdc++-v3/testsuite/20_util/bind/45924.cc b/libstdc++-v3/testsuite/20_util/bind/45924.cc new file mode 100644 index 000000000..27adb70c0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/45924.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <functional> + +// PR libstdc++/45924 + +struct f +{ + int operator()(int, int) const { return 0; } +}; + +void test01() +{ + int i = 0; + using namespace std::placeholders; + auto b = std::bind<int>(f(), _1, _2); + auto const bc(b); + b(i, i); + bc(i, i); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/20_util/bind/49058_1.cc b/libstdc++-v3/testsuite/20_util/bind/49058_1.cc new file mode 100644 index 000000000..fb34e0878 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/49058_1.cc @@ -0,0 +1,34 @@ +// { dg-options "-pedantic -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/>. + +#include <functional> + +// PR libstdc++/49058 + +struct F +{ + void + operator()(); +}; + +void f() +{ + std::bind( F() ); +} diff --git a/libstdc++-v3/testsuite/20_util/bind/49058_2.cc b/libstdc++-v3/testsuite/20_util/bind/49058_2.cc new file mode 100644 index 000000000..fc9d9a254 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/49058_2.cc @@ -0,0 +1,28 @@ +// { dg-options "-pedantic -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/>. + +#include <functional> + +// PR libstdc++/49058 + +void f() +{ + std::bind( []{} ); +} diff --git a/libstdc++-v3/testsuite/20_util/bind/all_bound.cc b/libstdc++-v3/testsuite/20_util/bind/all_bound.cc new file mode 100644 index 000000000..4335ee1d1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/all_bound.cc @@ -0,0 +1,39 @@ +// { dg-options "-std=gnu++0x" } +// 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +// Operations on empty function<> objects +void test01() +{ + bool test __attribute__((unused)) = true; + + VERIFY( std::bind(std::plus<int>(), 3, 5)() == 8 ); + VERIFY( std::bind(std::minus<int>(), 3, 5)() == -2 ); + VERIFY( std::bind<int>(std::plus<int>(), 3, 5)() == 8 ); + VERIFY( std::bind<int>(std::minus<int>(), 3, 5)() == -2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/conv_result.cc b/libstdc++-v3/testsuite/20_util/bind/conv_result.cc new file mode 100644 index 000000000..440a5276b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/conv_result.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +struct X +{ + typedef int result_type; + int operator()(int i) const { return i+1; } + bool b; +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::bind; + using std::ref; + ::X x = { true }; + + // test bind<R> form + bind<void>(ref(x), 1)(); + VERIFY( bind<long>(ref(x), 1)() == 2 ); + bind<void>(&::X::b, ref(x))(); + VERIFY( bind<int>(&::X::b, ref(x))() == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc b/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc new file mode 100644 index 000000000..d597a56fd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/cv_quals.cc @@ -0,0 +1,119 @@ +// 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/>. + +// 20.7.11 Function template bind + +// { dg-options "-std=gnu++0x" } + +#include <functional> +#include <testsuite_hooks.h> + +// target must be invoked with cv-quals of call wrapper + +struct X +{ + int operator()() { return 0; } + int operator()() const { return 1; } + int operator()() volatile { return 2; } + int operator()() const volatile { return 3; } + + int operator()(int, int, int) { return 0; } + int operator()(int, int, int) const { return 1; } + int operator()(int, int, int) volatile { return 2; } + int operator()(int, int, int) const volatile { return 3; } +}; + +using std::placeholders::_1; +using std::placeholders::_2; + +void test01() +{ + bool test __attribute__((unused)) = true; + + auto b0 = std::bind(X()); + VERIFY( b0() == 0 ); + + const auto b1 = std::bind(X()); + VERIFY( b1() == 1 ); + + volatile auto b2 = std::bind(X()); + VERIFY( b2() == 2 ); + + const volatile auto b3 = std::bind(X()); + VERIFY( b3() == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + auto b0 = std::bind<int>(X()); + VERIFY( b0() == 0 ); + + const auto b1 = std::bind<int>(X()); + VERIFY( b1() == 1 ); + + volatile auto b2 = std::bind<int>(X()); + VERIFY( b2() == 2 ); + + const volatile auto b3 = std::bind<int>(X()); + VERIFY( b3() == 3 ); +} + +void test03() +{ + bool test __attribute__((unused)) = true; + + auto b0 = std::bind(X(), 0, _1, _2); + VERIFY( b0(0, 0) == 0 ); + + const auto b1 = std::bind(X(), _1, 0, _2); + VERIFY( b1(0, 0) == 1 ); + + volatile auto b2 = std::bind(X(), _1, _2, 0); + VERIFY( b2(0, 0) == 2 ); + + const volatile auto b3 = std::bind(X(), _1, 0, _2); + VERIFY( b3(0, 0) == 3 ); +} + +void test04() +{ + bool test __attribute__((unused)) = true; + + auto b0 = std::bind<int>(X(), 0, _1, _2); + VERIFY( b0(0, 0) == 0 ); + + const auto b1 = std::bind<int>(X(), _1, 0, _2); + VERIFY( b1(0, 0) == 1 ); + + volatile auto b2 = std::bind<int>(X(), _1, _2, 0); + VERIFY( b2(0, 0) == 2 ); + + const volatile auto b3 = std::bind<int>(X(), _1, 0, _2); + VERIFY( b3(0, 0) == 3 ); +} + + +int main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc b/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc new file mode 100644 index 000000000..067d862b4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc @@ -0,0 +1,49 @@ +// 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/>. + +// { dg-options "-std=gnu++0x" } + +#include <functional> +#include <testsuite_hooks.h> + +struct X +{ + int operator()() const { return 0; } + int operator()() volatile { return 1; } + int operator()() const volatile { return 2; } + void operator()() { }; +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + const auto b0 = std::bind(X()); + VERIFY( b0() == 0 ); + + volatile auto b1 = std::bind(X()); + VERIFY( b1() == 1 ); + + const volatile auto b2 = std::bind(X()); + VERIFY( b2() == 2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/move.cc b/libstdc++-v3/testsuite/20_util/bind/move.cc new file mode 100644 index 000000000..d9485ad31 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/move.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++0x" } + +// 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 <functional> +#include <testsuite_hooks.h> + +// PR libstdc++/45924 + +struct f +{ + f() : i(0) { } + f(f&& r) : i(1) { r.i = -1; } + f(const f&) = delete; + int operator()() { return i; } + int i; +}; + +void test01() +{ + auto b = std::bind(f()); + VERIFY( b() == 1 ); + auto bc(std::move(b)); + VERIFY( bc() == 1 ); + VERIFY( b() == -1 ); +} + +void test02() +{ + auto b = std::bind<int>(f()); + VERIFY( b() == 1 ); + auto bc(std::move(b)); + VERIFY( bc() == 1 ); + VERIFY( b() == -1 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/20_util/bind/nested.cc b/libstdc++-v3/testsuite/20_util/bind/nested.cc new file mode 100644 index 000000000..ae3a16686 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/nested.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +// Operations on empty function<> objects +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::placeholders; + + int five = 5; + int seven = 7; + VERIFY( std::bind(std::multiplies<int>(), _1, + std::bind(std::minus<int>(), 6, _2))(five, seven) == -5 ); + VERIFY( std::bind(std::multiplies<int>(), _1, + std::bind(std::minus<int>(), 6, _2))(seven, five) == 7 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/placeholders.cc b/libstdc++-v3/testsuite/20_util/bind/placeholders.cc new file mode 100644 index 000000000..fc0d9c64f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/placeholders.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +// Operations on empty function<> objects +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::placeholders; + + int five = 5; + int seven = 7; + VERIFY( std::bind(std::minus<int>(), _1, _2)(five, seven) == -2 ); + VERIFY( std::bind(std::minus<int>(), _2, _1)(five, seven) == 2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/ref.cc b/libstdc++-v3/testsuite/20_util/bind/ref.cc new file mode 100644 index 000000000..6b41f1887 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/ref.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } +// 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/>. + +// 20.7.11 Function template bind + +#include <functional> +#include <testsuite_hooks.h> + +struct X +{ + X() : bar(17) {} + + int foo(int x, int y) { return bar + x + y; } + + int bar; + +private: + X(const X&); + X& operator=(const X&); +}; + +// Operations on empty function<> objects +void test01() +{ + bool test __attribute__((unused)) = true; + using std::bind; + using std::ref; + ::X x; + + VERIFY( bind(&::X::foo, ref(x), 1, 2)() == 20 ); + VERIFY( bind<int>(&::X::foo, ref(x), 1, 2)() == 20 ); + VERIFY( bind(&::X::bar, ref(x))() == 17 ); + VERIFY( bind<int>(&::X::bar, ref(x))() == 17 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/bind/ref2.cc b/libstdc++-v3/testsuite/20_util/bind/ref2.cc new file mode 100644 index 000000000..614943157 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/ref2.cc @@ -0,0 +1,63 @@ +// 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/>. + +// 20.7.11 Function template bind + +// { dg-options "-std=gnu++0x" } + +#include <functional> +#include <testsuite_hooks.h> + +using namespace std::placeholders; + +int inc(int& i) { return ++i; } + +void test01() +{ + bool test __attribute__((unused)) = true; + + int counter = 0; + std::bind(&inc, _1)(counter); + VERIFY(counter == 1 ); + std::bind(&inc, std::ref(counter))(); + VERIFY(counter == 2 ); +} + +struct Inc +{ + int operator()(int& i) const { return ++i; } + void operator()(int&&) const { } + + int f(int& i) const { return ++i; } +}; + +void test02() +{ + bool test __attribute__((unused)) = true; + + int counter = 0; + std::bind(Inc(), _1)(counter); + VERIFY(counter == 1 ); + std::bind(&Inc::f, Inc(), std::ref(counter))(); + VERIFY(counter == 2 ); +} + +int main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc new file mode 100644 index 000000000..060bf8715 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc @@ -0,0 +1,59 @@ +// 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/>. + +// 20.7.11 Function template bind + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <functional> + +using namespace std::placeholders; + +int inc(int& i) { return ++i; } + +void test01() +{ + const int dummy = 0; + std::bind(&inc, _1)(0); // { dg-error ""} + std::bind(&inc, std::ref(dummy))(); // { dg-error ""} + std::bind(&inc, dummy)(); // { dg-error ""} + std::bind(&inc, 0)(); // { dg-error ""} +} + +struct Inc +{ + int operator()(int& i) const { return ++i; } + void operator()(int&&) const { } + + int f(int&& i) const { return ++i; } +}; + +void test02() +{ + const int dummy = 0; + std::bind(Inc(), _1)(dummy); // { dg-error ""} + std::bind(&Inc::f, Inc(), std::ref(dummy))(); // { dg-error ""} +} + +int main() +{ + test01(); + test02(); +} + +// { dg-excess-errors "" } 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 new file mode 100644 index 000000000..93422ca84 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc @@ -0,0 +1,41 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2008, 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef int test_type1; + 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-1.cc b/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-1.cc new file mode 100644 index 000000000..94469d974 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-1.cc @@ -0,0 +1,117 @@ +// { dg-options "-std=gnu++0x" } +// +// Copyright (C) 2008, 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> + +#define JOIN( X, Y ) DO_JOIN( X, Y ) +#define DO_JOIN( X, Y ) DO_JOIN2(X,Y) +#define DO_JOIN2( X, Y ) X##Y + +#define COMMON_TYPE_TEST_1(type1, uid) \ + typedef common_type<type1>::type JOIN(test_t,uid); \ + VERIFY( (is_same<JOIN(test_t,uid), JOIN(test_t,uid)>::value) ); \ + typedef common_type<const type1>::type JOIN(test_t,JOIN(uid,c)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,c)), \ + JOIN(test_t,JOIN(uid,c))>::value) ); \ + typedef common_type<volatile type1>::type JOIN(test_t,JOIN(uid,v)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,v)), \ + JOIN(test_t,JOIN(uid,v))>::value) ); \ + typedef common_type<const volatile type1>::type JOIN(test_t,JOIN(uid,cv)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,cv)), \ + JOIN(test_t,JOIN(uid,cv))>::value) ); \ + typedef common_type<type1 &>::type JOIN(test_t,JOIN(uid,l)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,l)), \ + JOIN(test_t,JOIN(uid,l))>::value) ); \ + typedef common_type<const type1 &>::type JOIN(test_t,JOIN(uid,lc)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,lc)), \ + JOIN(test_t,JOIN(uid,lc))>::value) ); \ + typedef common_type<volatile type1 &>::type JOIN(test_t,JOIN(uid,lv)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,lv)), \ + JOIN(test_t,JOIN(uid,lv))>::value) ); \ + typedef common_type<const volatile type1 &>::type JOIN(test_t,JOIN(uid,lcv)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,lcv)), \ + JOIN(test_t,JOIN(uid,lcv))>::value) ); \ + typedef common_type<type1 &&>::type JOIN(test_t,JOIN(uid,r)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,r)), \ + JOIN(test_t,JOIN(uid,r))>::value) ); \ + typedef common_type<const type1 &&>::type JOIN(test_t,JOIN(uid,rc)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,rc)), \ + JOIN(test_t,JOIN(uid,rc))>::value) ); \ + typedef common_type<volatile type1 &&>::type JOIN(test_t,JOIN(uid,rv)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,rv)), \ + JOIN(test_t,JOIN(uid,rv))>::value) ); \ + typedef common_type<const volatile type1 &&>::type JOIN(test_t,JOIN(uid,rcv)); \ + VERIFY( (is_same<JOIN(test_t,JOIN(uid,rcv)), \ + JOIN(test_t,JOIN(uid,rcv))>::value) ) + +struct A { }; +struct B : A { }; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::common_type; + using std::is_same; + + // Positive tests. + COMMON_TYPE_TEST_1(int, 1); + COMMON_TYPE_TEST_1(double, 2); + COMMON_TYPE_TEST_1(A, 3); + COMMON_TYPE_TEST_1(B, 4); +} + +#define COMMON_TYPE_TEST_2_IMPL(type1, type2, type3, uid) \ + typedef common_type<type1, type2>::type JOIN(JOIN(test, uid),_t1); \ + typedef common_type<type2, type1>::type JOIN(JOIN(test, uid),_t2); \ + VERIFY( (is_same<JOIN(JOIN(test, uid),_t1), type3>::value) ); \ + VERIFY( (is_same<JOIN(JOIN(test, uid),_t2), type3>::value) ) + +#define NO_CV + +#define COMMON_TYPE_TEST_2(cv_qual, type1, type2, type3, uid) \ + COMMON_TYPE_TEST_2_IMPL(cv_qual type1, type2, type3, uid); \ + COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &, type2, type3, JOIN(uid,l)); \ + COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &&, type2, type3, JOIN(uid,r)) + +#define COMMON_TYPE_TEST_ALL_2(type1, type2, type3, uid) \ + COMMON_TYPE_TEST_2(NO_CV, type1, type2, type3, uid); \ + COMMON_TYPE_TEST_2(const, type1, type2, type3, uid); \ + COMMON_TYPE_TEST_2(volatile, type1, type2, type3, uid); \ + COMMON_TYPE_TEST_2(const volatile, type1, type2, type3, uid) + +void test02() +{ + bool test __attribute__((unused)) = true; + using std::common_type; + using std::is_same; + + COMMON_TYPE_TEST_ALL_2(int, int, int, 1); + COMMON_TYPE_TEST_ALL_2(int, double, double, 2); + COMMON_TYPE_TEST_2(NO_CV, A, A, A, 3); + COMMON_TYPE_TEST_2(const, A, A, const A, 4); + COMMON_TYPE_TEST_2(NO_CV, B, A, A, 5); +} + +int main() +{ + test01(); + test02(); + return 0; +} 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 000000000..b4a96e540 --- /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/conditional/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/conditional/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..854f46d6f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/conditional/requirements/explicit_instantiation.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2007-05-02 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct conditional<true, test_type, test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/conditional/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/conditional/requirements/typedefs.cc new file mode 100644 index 000000000..c1b145d80 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/conditional/requirements/typedefs.cc @@ -0,0 +1,41 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-05-02 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 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> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::conditional; + + typedef conditional<true, char, int>::type test1_type; + VERIFY( (std::is_same<test1_type, char>::value) ); + + typedef conditional<false, char, int>::type test2_type; + VERIFY( (std::is_same<test2_type, int>::value) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/decay/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/decay/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..6433d945b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/decay/requirements/explicit_instantiation.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2007-05-02 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct decay<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/decay/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/decay/requirements/typedefs.cc new file mode 100644 index 000000000..9a67ab47d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/decay/requirements/typedefs.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-05-03 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 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 <cstdlib> +#include <type_traits> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::decay; + using std::is_same; + + // Positive tests. + typedef decay<bool>::type test1_type; + VERIFY( (is_same<test1_type, bool>::value) ); + + // NB: DR 705. + typedef decay<const int>::type test2_type; + VERIFY( (is_same<test2_type, int>::value) ); + + typedef decay<int[4]>::type test3_type; + VERIFY( (is_same<test3_type, std::remove_extent<int[4]>::type*>::value) ); + + typedef void (fn_type) (); + typedef decay<fn_type>::type test4_type; + VERIFY( (is_same<test4_type, std::add_pointer<fn_type>::type>::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 000000000..204d4ebb6 --- /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 000000000..9113c031b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc @@ -0,0 +1,29 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2009-11-12 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2009, 2010, 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/>. + +// { dg-error "static assertion failed" "" { target *-*-* } 1134 } + +#include <utility> + +void test01() +{ + std::declval<int>(); // { dg-error "instantiated from here" } +} diff --git a/libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc b/libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc new file mode 100644 index 000000000..9d779ac9c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x " } +// { dg-do compile } + +// Copyright (C) 2011 Free Software Foundation +// +// 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> + +struct B { }; +struct D : B { }; + +// libstdc++/48631 +D d; +std::default_delete<B[]> db; +typedef decltype(db(&d)) type; // { dg-error "use of deleted function" } +// { dg-error "declared here" "" { target *-*-* } 83 } diff --git a/libstdc++-v3/testsuite/20_util/default_delete/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/default_delete/cons/constexpr.cc new file mode 100644 index 000000000..01fb28476 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/default_delete/cons/constexpr.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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_common_types.h> + +int main() +{ + __gnu_test::constexpr_defaulted_default_constructible test; + test.operator()<std::default_delete<int>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/arithmetic/1.cc b/libstdc++-v3/testsuite/20_util/duration/arithmetic/1.cc new file mode 100644 index 000000000..fb955abf1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/arithmetic/1.cc @@ -0,0 +1,93 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.3 Class template duration [time.duration] + +#include <chrono> +#include <testsuite_hooks.h> + +// 20.8.3.3 duration arithmetic [time.duration.arithmetic] (unary member ops) +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration<int> d0(3); + duration<int> d1 = -d0; + VERIFY(d0.count() == 3); + VERIFY(d1.count() == -3); + + duration<int> d2 = (+d0); + VERIFY(d2.count() == 3); + + duration<int> d3(++d2); + VERIFY(d2.count() == 4); + VERIFY(d3.count() == 4); + + duration<int> d4(d3++); + VERIFY(d3.count() == 5); + VERIFY(d4.count() == 4); + + duration<int> d5(--d4); + VERIFY(d4.count() == 3); + VERIFY(d5.count() == 3); + + duration<int> d6(d5--); + VERIFY(d5.count() == 2); + VERIFY(d6.count() == 3); +} + +// 20.8.3.3 duration arithmetic [time.duration.arithmetic] (binary member ops) +void +test02() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration<int> d7(3); + duration<int> d8(9); + d7 += d8; + VERIFY(d7.count() == 12); + VERIFY(d8.count() == 9); + + duration<int> d9(3); + duration<int> d10(9); + d9 -= d10; + VERIFY(d9.count() == -6); + VERIFY(d10.count() == 9); + + duration<int> d11(9); + int i = 3; + d11 *= i; + VERIFY(d11.count() == 27); + + duration<int> d12(12); + d12 /= i; + VERIFY(d12.count() == 4); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/arithmetic/2.cc b/libstdc++-v3/testsuite/20_util/duration/arithmetic/2.cc new file mode 100644 index 000000000..3940d6a67 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/arithmetic/2.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.3 Class template duration [time.duration] + +#include <chrono> +#include <testsuite_hooks.h> + +// 20.8.3.5 duration non-member arithmetic [time.duration.nonmember] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration<int> d0(12); + duration<int> d1(3); + int i = 3; + + duration<int> d2 = d0 + d1; + VERIFY(d2.count() == 15); + + duration<int> d3 = d0 - d1; + VERIFY(d3.count() == 9); + + duration<int> d4 = d0 * i; + VERIFY(d4.count() == 36); + + duration<int> d5 = i * d0; + VERIFY(d5.count() == 36); + + duration<int> d6 = d0 / i; + VERIFY(d6.count() == 4); + + int j = d0 / d1; + VERIFY(j == 4); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/arithmetic/dr934-1.cc b/libstdc++-v3/testsuite/20_util/duration/arithmetic/dr934-1.cc new file mode 100644 index 000000000..decf94c88 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/arithmetic/dr934-1.cc @@ -0,0 +1,48 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2009 Free Software Foundation +// +// 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 <chrono> + +class ClockTime +{ + typedef std::chrono::hours hours; + typedef std::chrono::minutes minutes; + typedef std::chrono::seconds seconds; + +public: + hours hours_; + minutes minutes_; + seconds seconds_; + + template<typename Rep, typename Period> + explicit + ClockTime(const std::chrono::duration<Rep, Period>& d) + : hours_ (std::chrono::duration_cast<hours> (d)), + minutes_(std::chrono::duration_cast<minutes>(d % hours(1))), + seconds_(std::chrono::duration_cast<seconds>(d % minutes(1))) { } +}; + +// DR 934. +void test01() +{ + std::chrono::duration<int> d; + ClockTime ct(d); +} diff --git a/libstdc++-v3/testsuite/20_util/duration/arithmetic/dr934-2.cc b/libstdc++-v3/testsuite/20_util/duration/arithmetic/dr934-2.cc new file mode 100644 index 000000000..ada8ba573 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/arithmetic/dr934-2.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2009 Free Software Foundation +// +// 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 <chrono> +#include <testsuite_hooks.h> + +// DR 934. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + const duration<int> d0(17); + duration<int> d3(d0); + d3 %= 5; + VERIFY( d3.count() == 2 ); + + const duration<int> d4(7); + duration<int> d5(d0); + d5 %= d4; + VERIFY( d5.count() == 3 ); + + const duration<int> d6 = d0 % 6; + VERIFY( d6.count() == 5 ); + + const duration<int> d7(11); + const duration<int> d8 = d0 % d7; + VERIFY( d8.count() == 6 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/comparison_operators/1.cc b/libstdc++-v3/testsuite/20_util/duration/comparison_operators/1.cc new file mode 100644 index 000000000..35151f2ad --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/comparison_operators/1.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.3 Class template duration [time.duration] + +#include <chrono> +#include <testsuite_hooks.h> + +// 20.8.3.6 duration comparisons [time.duration.comparisons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration<int> d0(12); + duration<int> d1(3); + duration<int> d2(3); + + VERIFY(d1 < d0); + VERIFY(d0 > d1); + + VERIFY(d0 != d1); + VERIFY(d1 == d2); + + VERIFY(d1 <= d2); + VERIFY(d1 >= d2); + + VERIFY(d1 <= d0); + VERIFY(d0 >= d1); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/comparison_operators/constexpr.cc b/libstdc++-v3/testsuite/20_util/duration/comparison_operators/constexpr.cc new file mode 100644 index 000000000..94338cee3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/comparison_operators/constexpr.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_comparison_operators test; + test.operator()<std::chrono::nanoseconds>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/1.cc b/libstdc++-v3/testsuite/20_util/duration/cons/1.cc new file mode 100644 index 000000000..2cd22a4a7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/1.cc @@ -0,0 +1,134 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.3 Class template duration [time.duration] + +#include <chrono> +#include <type_traits> +#include <testsuite_hooks.h> + +template<typename T> +struct type_emulator +{ + type_emulator() + : i(T(0)) { } + + type_emulator(T j) + : i(j) { } + + type_emulator(const type_emulator& e) + : i(e.i) { } + + type_emulator& + operator*=(type_emulator a) + { + i *= a.i; + return *this; + } + + type_emulator& + operator+=(type_emulator a) + { + i += a.i; + return *this; + } + + operator T () + { return i; } + + T i; +}; + +template<typename T> +bool +operator==(type_emulator<T> a, type_emulator<T> b) +{ return a.i == b.i; } + +template<typename T> +bool +operator<(type_emulator<T> a, type_emulator<T> b) +{ return a.i < b.i; } + +template<typename T> +type_emulator<T> +operator+(type_emulator<T> a, type_emulator<T> b) +{ return a += b; } + +template<typename T> +type_emulator<T> +operator*(type_emulator<T> a, type_emulator<T> b) +{ return a *= b; } + +namespace std +{ + template<typename T, typename U> + struct common_type<type_emulator<T>, U> + { typedef typename common_type<T,U>::type type; }; + + template<typename T, typename U> + struct common_type<U, type_emulator<T>> + { typedef typename common_type<U,T>::type type; }; + + template<typename T, typename U> + struct common_type<type_emulator<T>, type_emulator<U>> + { typedef typename common_type<T,U>::type type; }; + + namespace chrono + { + template<typename T> + struct treat_as_floating_point<type_emulator<T>> + : is_floating_point<T> + { }; + } +} + +typedef type_emulator<int> int_emulator; +typedef type_emulator<double> dbl_emulator; + +// 20.8.3.1 duration constructors [time.duration.cons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using std::chrono::duration; + + int r = 3; + duration<int> d1(r); + VERIFY(d1.count() == static_cast<duration<int>::rep>(r)); + + double s = 8.0; + duration<double> d2(s); + VERIFY(d2.count() == static_cast<duration<double>::rep>(s)); + + int_emulator ie(3); + duration<int_emulator> d3(ie); + VERIFY(d3.count() == static_cast<duration<int_emulator>::rep>(ie)); + + dbl_emulator de(4.0); + duration<dbl_emulator> d4(de); + VERIFY(d4.count() == static_cast<duration<dbl_emulator>::rep>(de)); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc b/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc new file mode 100644 index 000000000..56b4e4f41 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/1_neg.cc @@ -0,0 +1,41 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.3.1 duration constructors [time.duration.cons] + +#include <chrono> + +void +test01() +{ + std::chrono::duration<int> d1(1.0); // { dg-error "no matching" } +} + +void +test02() +{ + using namespace std::chrono; + + duration<int, std::micro> d2(8); + duration<int, std::milli> d2_copy(d2); // { dg-error "no matching" } +} + +// { dg-excess-errors "candidates are" } diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/2.cc b/libstdc++-v3/testsuite/20_util/duration/cons/2.cc new file mode 100644 index 000000000..820d76401 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/2.cc @@ -0,0 +1,119 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.3 Class template duration [time.duration] + +#include <chrono> +#include <type_traits> +#include <testsuite_hooks.h> + +template<typename T> +struct type_emulator +{ + type_emulator() : i(T(0)) { } + type_emulator(T j) : i(j) { } + type_emulator(const type_emulator& e) : i(e.i) { } + + type_emulator& operator*=(type_emulator a) + { i *= a.i; return *this; } + + type_emulator& operator+=(type_emulator a) + { i += a.i; return *this; } + + operator T () { return i; } + T i; +}; + +template<typename T> +bool operator==(type_emulator<T> a, type_emulator<T> b) +{ return a.i == b.i; } + +template<typename T> +bool operator<(type_emulator<T> a, type_emulator<T> b) +{ return a.i < b.i; } + +template<typename T> +type_emulator<T> operator+(type_emulator<T> a, type_emulator<T> b) +{ return a += b; } + +template<typename T> +type_emulator<T> operator*(type_emulator<T> a, type_emulator<T> b) +{ return a *= b; } + +namespace std +{ + template<typename T, typename U> + struct common_type<type_emulator<T>, U> + { typedef typename common_type<T,U>::type type; }; + + template<typename T, typename U> + struct common_type<U, type_emulator<T>> + { typedef typename common_type<U,T>::type type; }; + + template<typename T, typename U> + struct common_type<type_emulator<T>, type_emulator<U>> + { typedef typename common_type<T,U>::type type; }; + + namespace chrono + { + template<typename T> + struct treat_as_floating_point<type_emulator<T>> + : is_floating_point<T> + { }; + } +} + +typedef type_emulator<int> int_emulator; +typedef type_emulator<double> dbl_emulator; + +// 20.8.3.1 duration constructors [time.duration.cons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + duration<int> d0(3); + duration<int> d0_copy(d0); + VERIFY(d0_copy.count() == d0.count()); + + duration<int, std::milli> d1(5); + duration<int, std::micro> d1_copy(d1); + VERIFY(d1.count() * 1000 == d1_copy.count()); + + duration<double, std::micro> d2(8.0); + duration<double, std::milli> d2_copy(d2); + VERIFY(d2.count() == d2_copy.count() * 1000.0); + + duration<int_emulator, std::milli> d3(5); + duration<int_emulator, std::micro> d3_copy(d3); + VERIFY(d3.count() * 1000 == d3_copy.count()); + + duration<dbl_emulator, std::micro> d4(5.0); + duration<dbl_emulator, std::milli> d4_copy(d4); + VERIFY(d4.count() == d4_copy.count() * dbl_emulator(1000.0)); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/duration/cons/constexpr.cc new file mode 100644 index 000000000..ca7716f63 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/constexpr.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_default_constructible test1; + test1.operator()<std::chrono::seconds>(); + + __gnu_test::constexpr_single_value_constructible test2; + test2.operator()<std::chrono::seconds, std::chrono::seconds>(); + test2.operator()<std::chrono::seconds, std::chrono::seconds::rep>(); + test2.operator()<std::chrono::minutes, std::chrono::hours>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/dr974_neg.cc b/libstdc++-v3/testsuite/20_util/duration/cons/dr974_neg.cc new file mode 100644 index 000000000..4466d3009 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/dr974_neg.cc @@ -0,0 +1,33 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2009 Free Software Foundation +// +// 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.8.3.1 duration constructors [time.duration.cons] + +#include <chrono> + +// DR 974. +void test01() +{ + using namespace std::chrono; + + duration<double> d(3.5); + duration<int> i = d; // { dg-error "conversion" } +} diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/constexpr_functions.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/constexpr_functions.cc new file mode 100644 index 000000000..faeab3b93 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/constexpr_functions.cc @@ -0,0 +1,64 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +namespace __gnu_test +{ + struct constexpr_member_functions + { + template<typename _Ttesttype> + void + operator()() + { + struct _Concept + { + void __constraint() + { + constexpr auto v1 __attribute__((unused)) + = _Ttesttype::min(); + constexpr auto v2 __attribute__((unused)) + = _Ttesttype::max(); + constexpr auto v3 __attribute__((unused)) + = _Ttesttype::zero(); + + constexpr _Ttesttype obj { }; + constexpr auto v4 __attribute__((unused)) + = obj.count(); + constexpr auto v5 __attribute__((unused)) + = -obj; + constexpr auto v6 __attribute__((unused)) + = +obj; + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + __gnu_test::constexpr_member_functions test; + test.operator()<std::chrono::nanoseconds>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/explicit_instantiation/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/explicit_instantiation/explicit_instantiation.cc new file mode 100644 index 000000000..792d15cb9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/explicit_instantiation/explicit_instantiation.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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 <ratio> +#include <chrono> + +template class std::chrono::duration<int>; +template class std::chrono::duration<float, std::ratio<2,3>>; diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc new file mode 100644 index 000000000..5965f03b1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// 2008-07-31 Chris Fairles <chris.fairles@gmail.com> + +// Copyright (C) 2008, 2009, 2010, 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/>. + + +#include <chrono> + +void test01() +{ + // Check if rep is a duration type + typedef std::chrono::duration<int> rep_type; + typedef std::chrono::duration<rep_type> test_type; + test_type d; +} + +// { dg-error "rep cannot be a duration" "" { target *-*-* } 226 } +// { dg-error "instantiated from here" "" { target *-*-* } 31 } diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc new file mode 100644 index 000000000..d84ab9e8c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// 2008-07-31 Chris Fairles <chris.fairles@gmail.com> + +// Copyright (C) 2008, 2009, 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 <chrono> + +void test01() +{ + // Check if period is a ratio + typedef int rep_type; + typedef int period_type; + typedef std::chrono::duration<rep_type, period_type> test_type; + test_type d; +} + +// { dg-error "must be a specialization of ratio" "" { target *-*-* } 227 } +// { dg-error "instantiated from here" "" { target *-*-* } 32 } +// { dg-excess-errors "In instantiation of" } diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc new file mode 100644 index 000000000..7c73bf996 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// 2008-07-31 Chris Fairles <chris.fairles@gmail.com> + +// Copyright (C) 2008, 2009, 2010, 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/>. + + +#include <ratio> +#include <chrono> + +void test01() +{ + // Check if period is positive + typedef int rep_type; + typedef std::ratio<-1> period_type; + typedef std::chrono::duration<rep_type, period_type> test_type; + test_type d; +} + +// { dg-error "period must be positive" "" { target *-*-* } 229 } +// { dg-error "instantiated from here" "" { target *-*-* } 33 } diff --git a/libstdc++-v3/testsuite/20_util/duration_cast/constexpr.cc b/libstdc++-v3/testsuite/20_util/duration_cast/constexpr.cc new file mode 100644 index 000000000..b8a89aee9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration_cast/constexpr.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +int main() +{ + using namespace std::chrono; + + // non-constexpr + minutes mn1(6000); + hours hr1 __attribute__((unused)) = duration_cast<hours>(mn1); + + // constexpr + constexpr minutes mn2(6000); + constexpr hours hr2 __attribute__((unused)) = duration_cast<hours>(mn2); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/enable_if/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/enable_if/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..802a49984 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/enable_if/requirements/explicit_instantiation.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2007-05-02 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct enable_if<true>; +} diff --git a/libstdc++-v3/testsuite/20_util/enable_if/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/enable_if/requirements/typedefs.cc new file mode 100644 index 000000000..f17eebadd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/enable_if/requirements/typedefs.cc @@ -0,0 +1,32 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-05-02 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 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> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::enable_if; + + // Positive tests. + typedef enable_if<true, int>::type test1_type; +} diff --git a/libstdc++-v3/testsuite/20_util/enable_if/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/enable_if/requirements/typedefs_neg.cc new file mode 100644 index 000000000..6ab1fef33 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/enable_if/requirements/typedefs_neg.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-05-02 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 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> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::enable_if; + + // Negative tests. + typedef enable_if<false, int>::type test2_type; +} + +// { dg-error "does not name a type" "" { target *-*-* } 32 } diff --git a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/cons/constexpr.cc new file mode 100644 index 000000000..17f8c84d2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/cons/constexpr.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x -fno-inline -save-temps -g0" } +// { dg-final { scan-assembler-not "_ZNSt23enable_shared_from_thisIiEC2Ev" } } +// { dg-final { scan-assembler-not "_ZN7derivedC2Ev" } } + +// 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_common_types.h> + +struct derived : public std::enable_shared_from_this<int> +{ + constexpr derived() { } +}; + +int main() +{ + __gnu_test::constexpr_default_constructible test; + test.operator()<derived>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..9a18a507b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/requirements/explicit_instantiation.cc @@ -0,0 +1,23 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 2009 Free Software Foundation +// +// 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> + +template class std::enable_shared_from_this<int>; diff --git a/libstdc++-v3/testsuite/20_util/forward/1.cc b/libstdc++-v3/testsuite/20_util/forward/1.cc new file mode 100644 index 000000000..7d40416ff --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/forward/1.cc @@ -0,0 +1,43 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-07-10 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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 <memory> +#include <utility> + +template<class T, class A1, class A2> + std::shared_ptr<T> + factory(A1&& a1, A2&& a2) + { + return std::shared_ptr<T>(new T(std::forward<A1>(a1), + std::forward<A2>(a2))); + } + +struct A +{ + A(int&, const double&); +}; + +void g() +{ + int i = 2; + std::shared_ptr<A> sp1 = factory<A>(i, 1.414); +} diff --git a/libstdc++-v3/testsuite/20_util/forward/1_neg.cc b/libstdc++-v3/testsuite/20_util/forward/1_neg.cc new file mode 100644 index 000000000..6c007bee2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/forward/1_neg.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-07-10 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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 <memory> +#include <utility> + +template<class T, class A1, class A2> + std::shared_ptr<T> + factory(A1&& a1, A2&& a2) + { + return std::shared_ptr<T>(new T(std::forward<A1>(a1), + std::forward<A2>(a2))); // { dg-error "no matching function" } + } + +struct A +{ + A(int&, const double&); +}; + +void g() +{ + std::shared_ptr<A> sp1 = factory<A>(2, 1.414); // { dg-error "instantiated from here" } +} + +// { dg-excess-errors "" } diff --git a/libstdc++-v3/testsuite/20_util/forward/a.cc b/libstdc++-v3/testsuite/20_util/forward/a.cc new file mode 100644 index 000000000..296c9f449 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/forward/a.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 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 <list> +#include <testsuite_hooks.h> + +template <class T> + struct C + { + T t_; + + template <class U, + class = typename std::enable_if + < + !std::is_lvalue_reference<U>::value + >::type> + C(U&& u) : t_(std::forward<T>(std::move(u).get())) {} + }; + +class A +{ + int data_; +public: + explicit + A(int data = 1) + : data_(data) {} + + ~A() { data_ = -1; } + + void test() const + { + bool test __attribute__((unused)) = true; + VERIFY( data_ == 3 ); + } +}; + +class Awrap +{ + const A& a_; +public: + explicit Awrap(const A& a) : a_(a) { } + const A& get() const { return a_; } +}; + +template <class C> + void test(C c) + { + c.t_.test(); + } + +// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html +// Test A. +int main() +{ + std::list<C<const A&> > list; + A a(3); + C<const A&> c((Awrap(a))); + list.push_back(c); + test(c); + test(list.front()); +} diff --git a/libstdc++-v3/testsuite/20_util/forward/b.cc b/libstdc++-v3/testsuite/20_util/forward/b.cc new file mode 100644 index 000000000..4168800b4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/forward/b.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 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 <list> +#include <testsuite_hooks.h> + +template <class T> + struct C + { + T t_; + + template <class U, + class = typename std::enable_if + < + !std::is_lvalue_reference<U>::value + >::type> + C(U&& u) : t_(std::forward<T>(std::move(u).get())) {} + }; + +class A +{ + int data_; +public: + explicit + A(int data = 1) + : data_(data) { } + + ~A() { data_ = -1; } + + void test() const + { + bool test __attribute__((unused)) = true; + VERIFY( data_ == 3 ); + } +}; + +class Awrap +{ + A a_; +public: + explicit Awrap(const A& a) : a_(a) { } + A get() const { return a_; } +}; + +template <class C> +void test(C c) +{ + c.t_.test(); +} + +// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html +// Test B. +int main() +{ + std::list<C<A> > list; + A a(3); + C<A> c((Awrap(a))); + list.push_back(c); + test(c); + test(list.front()); +} diff --git a/libstdc++-v3/testsuite/20_util/forward/c_neg.cc b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc new file mode 100644 index 000000000..50bfbf028 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc @@ -0,0 +1,78 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010, 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/>. + +// { dg-error "static assertion failed" "" { target *-*-* } 69 } + +#include <list> + +template <class T> + struct C + { + T t_; + + template <class U, + class = typename std::enable_if + < + !std::is_lvalue_reference<U>::value + >::type> + C(U&& u) : t_(std::forward<T>(std::move(u).get())) {} + }; + +class A +{ + int data_; +public: + explicit + A(int data = 1) + : data_(data) { } + + ~A() { data_ = -1; } + + void test() const + { + __builtin_abort(); + } +}; + +class Awrap +{ + const A& a_; +public: + explicit Awrap(const A& a) : a_(a) {} + const A /* & */ get() const { return a_; } +}; + +template <class C> + void test(C c) + { + c.t_.test(); + } + +// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html +// Test C. +int main() +{ + std::list<C<const A&> > list; + A a(3); + C<const A&> c((Awrap(a))); + list.push_back(c); + test(c); + test(list.front()); +} diff --git a/libstdc++-v3/testsuite/20_util/forward/d.cc b/libstdc++-v3/testsuite/20_util/forward/d.cc new file mode 100644 index 000000000..c2c7eb3c8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/forward/d.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } + +// 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 <list> +#include <testsuite_hooks.h> + +template <class T> + struct C + { + T t_; + + template <class U, + class = typename std::enable_if + < + !std::is_lvalue_reference<U>::value + >::type> + C(U&& u) : t_(std::forward<T>(std::move(u).get())) { } + }; + +class A +{ + int data_; +public: + explicit + A(int data = 1) + : data_(data) { } + + ~A() { data_ = -1; } + + void test() const + { + bool test __attribute__((unused)) = true; + VERIFY( data_ == 3 ); + } +}; + +class Awrap +{ + A& a_; +public: + explicit Awrap(A& a) : a_(a) { } + const A& get() const { return a_; } + A& get() { return a_; } +}; + +template <class C> + void test(C c) + { + c.t_.test(); + } + +// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html +// Test D. +int main() +{ + std::list<C<const A&> > list; + A a(3); + C<const A&> c((Awrap(a))); + list.push_back(c); + test(c); + test(list.front()); +} diff --git a/libstdc++-v3/testsuite/20_util/forward/e.cc b/libstdc++-v3/testsuite/20_util/forward/e.cc new file mode 100644 index 000000000..4d89cd1a8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/forward/e.cc @@ -0,0 +1,54 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <utility> + +template <class T> + struct C + { + T t_; + + C() { } + + template <class U, + class = typename std::enable_if + < + !std::is_lvalue_reference<U>::value + >::type> + C(U&& u) : t_(std::forward<T>(std::move(u).get())) { } + + C(C&& c) : t_(std::forward<T>(c.t_)) { } + }; + +template <class T> + struct Derived + : C<T> + { + Derived() { } + Derived(Derived&& d) : C<T>(std::forward<C<T>>(d)) { } + }; + +// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html +// Test E. +int main() +{ + Derived<int> d; + Derived<int> d2(std::move(d)); +} diff --git a/libstdc++-v3/testsuite/20_util/forward/f_neg.cc b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc new file mode 100644 index 000000000..418a469df --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc @@ -0,0 +1,90 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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/>. + +// { dg-error "static assertion failed" "" { target *-*-* } 69 } + +#include <utility> + +template <class T> + struct C + { + T t_; + + C() {} + + explicit C(const T& t) : t_(t) { } + + template <class U, + class = typename std::enable_if + < + std::is_convertible<U, T>::value + >::type> + C(C<U>&& c) : t_(std::forward<T>(c.t_)) { } + }; + +class B; + +class A +{ + int data_; + + friend class B; +public: + explicit + A(int data = 1) + : data_(data) { } + + ~A() { data_ = -1; } + + void test() const + { + __builtin_abort(); + } +}; + +class B +{ + int data_; +public: + explicit + B(int data = 1) + : data_(data) { } + + B(const A& a) : data_(a.data_) { } + + B(A&& a) : data_(a.data_) { a.data_ = 100; } + + ~B() { data_ = -1; } + + void test() const + { + __builtin_abort(); + } +}; + +// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html +// Test F. +int main() +{ + A a(3); + C<A> ca(a); + C<const B&> cb(std::move(ca)); + cb.t_.test(); +} diff --git a/libstdc++-v3/testsuite/20_util/forward/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/forward/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..88ba9e548 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/forward/requirements/explicit_instantiation.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2007-07-10 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing utility with NO OTHER INCLUDES. + +#include <utility> + +namespace std +{ + typedef short test_type; + template test_type&& forward<test_type>(test_type&&); +} diff --git a/libstdc++-v3/testsuite/20_util/function/1.cc b/libstdc++-v3/testsuite/20_util/function/1.cc new file mode 100644 index 000000000..89a22542b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/1.cc @@ -0,0 +1,94 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> +// +// Copyright (C) 2005, 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/>. + +// 20.7.15 polymorphic function object wrapper +#include <functional> +#include <testsuite_hooks.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Operations on empty function<> objects +void test01() +{ + using std::function; + using std::bad_function_call; + + // Default-construction + function<int(float)> f1; + VERIFY( ((bool)f1 == false) ); + VERIFY( !f1 ); + VERIFY( f1 == 0 ); + VERIFY( 0 == f1 ); + VERIFY( !(f1 != 0) ); + VERIFY( !(0 != f1) ); + + // Copy-construction + function<int(float)> f2(f1); + VERIFY( !f2 ); + + // Construct with NULL pointer + function<int(float)> f3(0); + VERIFY( !f3 ); + + // Assignment + f1 = f2; + VERIFY( !f1); + + // Assignment to NULL pointer + f1 = 0; + VERIFY( !f1 ); + + // Swap + swap(f1, f2); + VERIFY( !f1 ); + VERIFY( !f2 ); + + // Invocation should throw bad_function_call + bool thrown = false; + try + { + f1(3.14159f); + VERIFY( false ); + } + catch (bad_function_call) + { + thrown = true; + } + VERIFY( thrown ); + + // target_type returns typeid(void) + VERIFY( f1.target_type() == typeid(void) ); + + // target() always returns a NULL pointer + VERIFY( f1.target<int (*)(float)>() == 0); + + // Check const version + const function<int(float)>& f1c = f1; + VERIFY( f1c.target<int (*)(float)>() == 0 ); + VERIFY( !f1c ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/2.cc b/libstdc++-v3/testsuite/20_util/function/2.cc new file mode 100644 index 000000000..f2866d085 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/2.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> +// +// Copyright (C) 2005, 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/>. + +// 20.7.15 polymorphic function object wrapper +#include <functional> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put function pointers into function<> wrappers +void test02() +{ + using std::function; + + function<int(float)> f1(truncate_float); + VERIFY( f1 ); + VERIFY( !!f1 ); + VERIFY( !(f1 == 0) ); + VERIFY( !(0 == f1) ); + VERIFY( f1 != 0 ); + VERIFY( 0 != f1 ); + + // Copy-construction + function<int(float)> f2(f1); + VERIFY( f2 ); + + // Invocation + VERIFY( f1(3.1f) == 3 ); + VERIFY( f2(3.1f) == 3 ); + + // Assignment to zero + f1 = 0; + VERIFY( !f1 ); + + // Swap + f1.swap(f2); + VERIFY( f1 ); + VERIFY( !f2 ); + VERIFY( f1(3.1f) == 3 ); + + // Assignment from a function pointer + f2 = truncate_float; + VERIFY( f2(3.1f) == 3 ); + + // target_type and target() functions + const function<int(float)>& f1c = f1; + VERIFY( typeid(int(*)(float)) == f1.target_type() ); + VERIFY( f2.target<int(*)(float)>() != 0 ); + VERIFY( *f2.target<int(*)(float)>() == &truncate_float ); + VERIFY( f1c.target<int(*)(float)>() != 0 ); + VERIFY( *f1c.target<int(*)(float)>() == &truncate_float ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/3.cc b/libstdc++-v3/testsuite/20_util/function/3.cc new file mode 100644 index 000000000..7f9239015 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/3.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> +// +// Copyright (C) 2005, 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/>. + +// 20.7.15 polymorphic function object wrapper +#include <functional> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put nearly-matching function pointers into function<> wrappers +void test03() +{ + using std::function; + + function<int(float)> f1(truncate_double); + VERIFY( f1 ); + VERIFY( !!f1 ); + VERIFY( !(f1 == 0) ); + VERIFY( !(0 == f1) ); + VERIFY( f1 != 0 ); + VERIFY( 0 != f1 ); + + // Copy-construction + function<int(float)> f2(f1); + VERIFY( f2 ); + + // Invocation + VERIFY( f1(3.1f) == 3 ); + VERIFY( f2(3.1f) == 3 ); + + // Assignment to zero + f1 = 0; + VERIFY( !f1 ); + + // Swap + f1.swap(f2); + VERIFY( f1 ); + VERIFY( !f2 ); + VERIFY( f1(3.1f) == 3 ); + + // Assignment from a function pointer + f2 = truncate_double; + VERIFY( f2(3.1f) == 3 ); + + // target_type and target() functions + const function<int(float)>& f1c = f1; + VERIFY( typeid(long(*)(double)) == f1.target_type() ); + VERIFY( f2.target<long(*)(double)>() != 0 ); + VERIFY( *f2.target<long(*)(double)>() == &truncate_double ); + VERIFY( f1c.target<long(*)(double)>() != 0 ); + VERIFY( *f1c.target<long(*)(double)>() == &truncate_double ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/4.cc b/libstdc++-v3/testsuite/20_util/function/4.cc new file mode 100644 index 000000000..824d17f59 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/4.cc @@ -0,0 +1,82 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> +// +// Copyright (C) 2005, 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/>. + +// 20.7.15 polymorphic function object wrapper +#include <functional> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put function objects into function<> wrappers +void test04() +{ + using std::function; + + do_truncate_float_t truncate_float; + + function<int(float)> f1(truncate_float); + VERIFY( f1 ); + VERIFY( !!f1 ); + VERIFY( !(f1 == 0) ); + VERIFY( !(0 == f1) ); + VERIFY( f1 != 0 ); + VERIFY( 0 != f1 ); + + // Copy-construction + function<int(float)> f2(f1); + VERIFY( f2 ); + + // Invocation + VERIFY( f1(3.1f) == 3 ); + VERIFY( f2(3.1f) == 3 ); + + // Assignment to zero + f1 = 0; + VERIFY( !f1 ); + + // Swap + f1.swap(f2); + VERIFY( f1 ); + VERIFY( !f2 ); + VERIFY( f1(3.1f) == 3 ); + + // Assignment from a function pointer + f2 = do_truncate_float_t(); + VERIFY( f2(3.1f) == 3 ); + + // target_type and target() functions + const function<int(float)>& f1c = f1; + VERIFY( typeid(do_truncate_float_t) == f1.target_type() ); + VERIFY( f2.target<do_truncate_float_t>() != 0 ); + VERIFY( f1c.target<do_truncate_float_t>() != 0 ); +} + +int main() +{ + test04(); + + VERIFY( do_truncate_double_t::live_objects == 0 ); + VERIFY( do_truncate_float_t::live_objects == 0 ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/43397.cc b/libstdc++-v3/testsuite/20_util/function/43397.cc new file mode 100644 index 000000000..d76a27f34 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/43397.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } +// 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/>. + +// 20.8.15 polymorphic function object wrapper + +#include <functional> +#include <testsuite_hooks.h> + +struct Foo +{ + Foo() { } + short operator() ( int && ) { return 1; } + short operator() ( int && ) const { return 2; } + short operator() ( int && ) volatile { return 3; } + short operator() ( int && ) const volatile { return 4; } + short func( int && ) { return 5; } + short func_c( int && ) const { return 6; } + short func_v( int && ) volatile { return 7; } + short func_cv( int && ) const volatile { return 8; } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + using std::function; + using std::ref; + + Foo foo; + Foo const foo_c; + Foo volatile foo_v; + Foo const volatile foo_cv; + + std::function< int ( int && ) > f1( ref(foo) ); + VERIFY( f1(0) == 1 ); + + std::function< int ( int && ) > f2( ref(foo_c) ); + VERIFY( f2(0) == 2 ); + + std::function< int ( int && ) > f3( ref(foo_v) ); + VERIFY( f3(0) == 3 ); + + std::function< int ( int && ) > f4( ref(foo_cv) ); + VERIFY( f4(0) == 4 ); + + std::function< int ( Foo &, int && ) > f5( &Foo::func ) ; + VERIFY( f5(foo, 0) == 5 ); + + std::function< int ( Foo const &, int && ) > f6( &Foo::func_c ) ; + VERIFY( f6(foo_c, 0) == 6 ); + + std::function< int ( Foo volatile &, int && ) > f7( &Foo::func_v ) ; + VERIFY( f7(foo_v, 0) == 7 ); + + std::function< int ( Foo const volatile &, int && ) > f8( &Foo::func_cv ) ; + VERIFY( f8(foo_cv, 0) == 8 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/48541.cc b/libstdc++-v3/testsuite/20_util/function/48541.cc new file mode 100644 index 000000000..f8123676f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/48541.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 +// <http://www.gnu.org/licenses/>. + +// libstdc++/48451 + +#include <functional> + +struct X { + void operator () () const { } + float operator & () const { return 1.2345; } +}; + +void test01() +{ + X x; + std::function<void()> f(x); + f(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/5.cc b/libstdc++-v3/testsuite/20_util/function/5.cc new file mode 100644 index 000000000..b86b198f0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/5.cc @@ -0,0 +1,107 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> +// +// Copyright (C) 2005, 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/>. + +// 20.7.15 polymorphic function object wrapper +#include <functional> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put member pointers into function<> wrappers +void test05() +{ + using std::function; + + X x; + x.bar = 17; + + function<int(X&)> frm(&X::bar); + VERIFY( frm ); + VERIFY( frm(x) == 17 ); + VERIFY( typeid(int X::*) == frm.target_type() ); + VERIFY( *frm.target<int X::*>() == &X::bar ); + + function<int(X&)> fr(&X::foo); + VERIFY( fr ); + VERIFY( fr(x) == 1 ); + VERIFY( typeid(int (X::*)()) == fr.target_type() ); + VERIFY( *fr.target<int (X::*)()>() == &X::foo ); + + function<int(const X&)> frc(&X::foo_c); + VERIFY( frc ); + VERIFY( frc(x) == 2 ); + VERIFY( typeid(int (X::*)() const) == frc.target_type() ); + VERIFY( *frc.target<int (X::*)() const >() == &X::foo_c ); + + function<int(volatile X&)> frv(&X::foo_v); + VERIFY( frv ); + VERIFY( frv(x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == frv.target_type() ); + VERIFY( *frv.target<int (X::*)() volatile >() == &X::foo_v ); + VERIFY( frv.target<int (X::*)() const volatile>() == 0 ); + + function<int(const volatile X&)> frcv(&X::foo_cv); + VERIFY( frcv ); + VERIFY( frcv(x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() ); + VERIFY( *frcv.target<int (X::*)() const volatile >() == &X::foo_cv ); + VERIFY( frcv.target<int (X::*)() const>() == 0 ); + + function<int(X*)> grm(&X::bar); + VERIFY( grm ); + VERIFY( grm(&x) == 17 ); + VERIFY( typeid(int X::*) == grm.target_type() ); + VERIFY( *grm.target<int X::*>() == &X::bar ); + + function<int(X*)> gr(&X::foo); + VERIFY( gr ); + VERIFY( gr(&x) == 1 ); + VERIFY( typeid(int (X::*)()) == gr.target_type() ); + VERIFY( *gr.target<int (X::*)()>() == &X::foo ); + + function<int(const X*)> grc(&X::foo_c); + VERIFY( grc ); + VERIFY( grc(&x) == 2 ); + VERIFY( typeid(int (X::*)() const) == grc.target_type() ); + VERIFY( *grc.target<int (X::*)() const >() == &X::foo_c ); + + function<int(volatile X*)> grv(&X::foo_v); + VERIFY( grv ); + VERIFY( grv(&x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == grv.target_type() ); + VERIFY( *grv.target<int (X::*)() volatile >() == &X::foo_v ); + VERIFY( grv.target<int (X::*)() const volatile>() == 0 ); + + function<int(const volatile X*)> grcv(&X::foo_cv); + VERIFY( grcv ); + VERIFY( grcv(&x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() ); + VERIFY( *grcv.target<int (X::*)() const volatile >() == &X::foo_cv ); + VERIFY( grcv.target<int (X::*)() const>() == 0 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/6.cc b/libstdc++-v3/testsuite/20_util/function/6.cc new file mode 100644 index 000000000..47d2c1f9b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/6.cc @@ -0,0 +1,82 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> +// +// Copyright (C) 2005, 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/>. + +// 20.7.15 polymorphic function object wrapper +#include <functional> +#include <testsuite_hooks.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +struct secret {}; + +struct noncopyable_function_object_type +{ + noncopyable_function_object_type(secret) {} + + int operator()() const { return 42; } + int operator()() { return 17; } + + private: + noncopyable_function_object_type(); + noncopyable_function_object_type(const noncopyable_function_object_type&); + void operator=(const noncopyable_function_object_type&); +}; + +// Put reference_wrappers into function<> wrappers +void test06() +{ + using std::function; + using std::ref; + using std::cref; + + secret password; + noncopyable_function_object_type x(password); + + function<int()> f(ref(x)); + VERIFY( f ); + VERIFY( f() == 17 ); + VERIFY( f.target_type() == typeid(noncopyable_function_object_type) ); + VERIFY( f.target<noncopyable_function_object_type>() == &x ); + + function<int()> g = f; + VERIFY( g ); + VERIFY( g() == 17 ); + VERIFY( g.target_type() == typeid(noncopyable_function_object_type) ); + VERIFY( g.target<noncopyable_function_object_type>() == &x ); + + function<int()> h = cref(x); + VERIFY( h ); + VERIFY( h() == 42 ); + VERIFY( h.target_type() == typeid(noncopyable_function_object_type) ); + VERIFY( h.target<const noncopyable_function_object_type>() == &x ); + VERIFY( h.target<const noncopyable_function_object_type>() == &x ); + + const function<int()>& hc = h; + VERIFY( h.target<noncopyable_function_object_type>() == 0 ); + VERIFY( hc.target<noncopyable_function_object_type>() == &x ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/7.cc b/libstdc++-v3/testsuite/20_util/function/7.cc new file mode 100644 index 000000000..3b922116b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/7.cc @@ -0,0 +1,82 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> +// +// Copyright (C) 2005, 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/>. + +// 20.7.15 polymorphic function object wrapper +#include <functional> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put reference_wrappers to function pointers into function<> wrappers +void test07() +{ + using std::function; + using std::ref; + using std::cref; + + int (*fptr)(float) = truncate_float; + + function<int(float)> f1(ref(fptr)); + VERIFY( f1 ); + VERIFY( !!f1 ); + VERIFY( !(f1 == 0) ); + VERIFY( !(0 == f1) ); + VERIFY( f1 != 0 ); + VERIFY( 0 != f1 ); + + // Invocation + VERIFY( f1(3.1f) == 3 ); + + // target_type and target() functions + const function<int(float)>& f1c = f1; + VERIFY( typeid(int(*)(float)) == f1.target_type() ); + VERIFY( f1.target<int(*)(float)>() != 0 ); + VERIFY( f1.target<int(*)(float)>() == &fptr ); + VERIFY( f1c.target<int(*)(float)>() != 0 ); + VERIFY( f1c.target<int(*)(float)>() == &fptr ); + + function<int(float)> f2(cref(fptr)); + VERIFY( f2 ); + VERIFY( !!f2 ); + VERIFY( !(f2 == 0) ); + VERIFY( !(0 == f2) ); + VERIFY( f2 != 0 ); + VERIFY( 0 != f2 ); + + // Invocation + VERIFY( f2(3.1f) == 3 ); + + // target_type and target() functions + const function<int(float)>& f2c = f2; + VERIFY( typeid(int(*)(float)) == f2.target_type() ); + VERIFY( f2.target<int(*)(float)>() == 0 ); + VERIFY( f2.target<int(* const)(float)>() == &fptr ); + VERIFY( f2c.target<int(*)(float)>() != 0 ); + VERIFY( f2c.target<int(*)(float)>() == &fptr ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/8.cc b/libstdc++-v3/testsuite/20_util/function/8.cc new file mode 100644 index 000000000..620f61610 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/8.cc @@ -0,0 +1,148 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> +// +// Copyright (C) 2005, 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/>. + +// 20.7.15 polymorphic function object wrapper +#include <functional> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put reference_wrappers to member pointers +void test08() +{ + using std::function; + using std::ref; + using std::cref; + + int X::* X_bar = &X::bar; + int (X::* X_foo)() = &X::foo; + int (X::* X_foo_c)() const = &X::foo_c; + int (X::* X_foo_v)() volatile = &X::foo_v; + int (X::* X_foo_cv)() const volatile = &X::foo_cv; + + X x; + x.bar = 17; + + function<int(X&)> frm(ref(X_bar)); + VERIFY( frm ); + VERIFY( frm(x) == 17 ); + VERIFY( typeid(int X::*) == frm.target_type() ); + VERIFY( frm.target<int X::*>() == &X_bar ); + + function<int(X&)> fr(ref(X_foo)); + VERIFY( fr ); + VERIFY( fr(x) == 1 ); + VERIFY( typeid(int (X::*)()) == fr.target_type() ); + VERIFY( fr.target<int (X::*)()>() == &X_foo ); + + function<int(const X&)> frc(ref(X_foo_c)); + VERIFY( frc ); + VERIFY( frc(x) == 2 ); + VERIFY( typeid(int (X::*)() const) == frc.target_type() ); + VERIFY( frc.target<int (X::*)() const >() == &X_foo_c ); + + function<int(volatile X&)> frv(ref(X_foo_v)); + VERIFY( frv ); + VERIFY( frv(x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == frv.target_type() ); + VERIFY( *frv.target<int (X::*)() volatile >() == X_foo_v ); + VERIFY( frv.target<int (X::*)() const volatile>() == 0 ); + + function<int(const volatile X&)> frcv(ref(X_foo_cv)); + VERIFY( frcv ); + VERIFY( frcv(x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() ); + VERIFY( *frcv.target<int (X::*)() const volatile >() == X_foo_cv ); + VERIFY( frcv.target<int (X::*)() const>() == 0 ); + + function<int(X*)> grm(ref(X_bar)); + VERIFY( grm ); + VERIFY( grm(&x) == 17 ); + VERIFY( typeid(int X::*) == grm.target_type() ); + VERIFY( *grm.target<int X::*>() == X_bar ); + + function<int(X*)> gr(ref(X_foo)); + VERIFY( gr ); + VERIFY( gr(&x) == 1 ); + VERIFY( typeid(int (X::*)()) == gr.target_type() ); + VERIFY( *gr.target<int (X::*)()>() == X_foo ); + + function<int(const X*)> grc(ref(X_foo_c)); + VERIFY( grc ); + VERIFY( grc(&x) == 2 ); + VERIFY( typeid(int (X::*)() const) == grc.target_type() ); + VERIFY( *grc.target<int (X::*)() const >() == X_foo_c ); + + function<int(volatile X*)> grv(ref(X_foo_v)); + VERIFY( grv ); + VERIFY( grv(&x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == grv.target_type() ); + VERIFY( *grv.target<int (X::*)() volatile >() == X_foo_v ); + VERIFY( grv.target<int (X::*)() const volatile>() == 0 ); + + function<int(const volatile X*)> grcv(ref(X_foo_cv)); + VERIFY( grcv ); + VERIFY( grcv(&x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() ); + VERIFY( *grcv.target<int (X::*)() const volatile >() == X_foo_cv ); + VERIFY( grcv.target<int (X::*)() const>() == 0 ); + + function<int(X&)> hrm(cref(X_bar)); + VERIFY( hrm ); + VERIFY( hrm(x) == 17 ); + VERIFY( typeid(int X::*) == hrm.target_type() ); + VERIFY( hrm.target<int X::*>() == 0 ); + VERIFY( hrm.target<int X::* const>() == &X_bar ); + + function<int(X&)> hr(cref(X_foo)); + VERIFY( hr ); + VERIFY( hr(x) == 1 ); + VERIFY( typeid(int (X::*)()) == hr.target_type() ); + VERIFY( hr.target<int (X::* const)()>() == &X_foo ); + + function<int(const X&)> hrc(cref(X_foo_c)); + VERIFY( hrc ); + VERIFY( hrc(x) == 2 ); + VERIFY( typeid(int (X::*)() const) == hrc.target_type() ); + VERIFY( hrc.target<int (X::* const)() const >() == &X_foo_c ); + + function<int(volatile X&)> hrv(cref(X_foo_v)); + VERIFY( hrv ); + VERIFY( hrv(x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == hrv.target_type() ); + VERIFY( hrv.target<int (X::* const)() volatile >() == &X_foo_v ); + VERIFY( hrv.target<int (X::* const)() const volatile>() == 0 ); + + function<int(const volatile X&)> hrcv(cref(X_foo_cv)); + VERIFY( hrcv ); + VERIFY( hrcv(x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == hrcv.target_type() ); + VERIFY( hrcv.target<int (X::* const)() const volatile >() == &X_foo_cv ); + VERIFY( hrcv.target<int (X::* const)() const>() == 0 ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/9.cc b/libstdc++-v3/testsuite/20_util/function/9.cc new file mode 100644 index 000000000..474ce6145 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/9.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> +// +// Copyright (C) 2005, 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/>. + +// 20.7.15 polymorphic function object wrapper +#include <functional> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put function objects into a void-returning function<> wrapper +void test09() +{ + using std::function; + using std::ref; + using std::cref; + + int (X::*X_foo_c)() const = &X::foo_c; + function<void(X&)> f(&X::bar); + f = &X::foo; + f = ref(X_foo_c); + f = cref(X_foo_c); + + function<void(float)> g = &truncate_float; + g = do_truncate_float_t(); +} + +int main() +{ + test09(); + + VERIFY( do_truncate_double_t::live_objects == 0 ); + VERIFY( do_truncate_float_t::live_objects == 0 ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/assign/move.cc b/libstdc++-v3/testsuite/20_util/function/assign/move.cc new file mode 100644 index 000000000..a2ab96245 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/assign/move.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++0x" } + +// 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 <functional> +#include <testsuite_hooks.h> + +int f1() { return 1; } +struct { int operator()() { return 2; } } f2; + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::function<int()> function; + + function fo(f1); + function fo1; + fo1 = (std::move(fo)); + VERIFY( static_cast<bool>(fo1) ); + VERIFY( fo1() == 1 ); + + fo = function(f2); + function fo2; + fo2 = (std::move(fo)); + VERIFY( static_cast<bool>(fo2) ); + VERIFY( fo2() == 2 ); +} + +int main() +{ + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/assign/move_target.cc b/libstdc++-v3/testsuite/20_util/function/assign/move_target.cc new file mode 100644 index 000000000..0a1c189e5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/assign/move_target.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } + +// 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 <functional> + +struct moveable +{ + moveable() = default; + ~moveable() = default; + // target object must be CopyConstructible, + // but should not be copied during this test + moveable(const moveable& c) { throw "copied"; } + moveable& operator=(const moveable&) = delete; + moveable(moveable&&) { } + + void operator()() const { } +}; + +void test01() +{ + std::function<void ()> f; + f = moveable(); + f(); +} + +int main() +{ + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/cmp/cmp_neg.cc b/libstdc++-v3/testsuite/20_util/function/cmp/cmp_neg.cc new file mode 100644 index 000000000..28c0e12d1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/cmp/cmp_neg.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2009, 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/>. + +// { dg-prune-output "include" } + +#include <functional> + +void test01() +{ + std::function<void()> f1; + std::function<void()> f2; + f1 == f2; // { dg-error "no match" } + f1 != f2; // { dg-error "no match" } +} +// { dg-excess-errors "candidates are" } diff --git a/libstdc++-v3/testsuite/20_util/function/cons/move.cc b/libstdc++-v3/testsuite/20_util/function/cons/move.cc new file mode 100644 index 000000000..43d71858c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/cons/move.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } + +// 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 <functional> +#include <testsuite_hooks.h> + +int f1() { return 1; } +struct { int operator()() { return 2; } } f2; + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::function<int()> function; + + function fo(f1); + function fo1(std::move(fo)); + VERIFY( static_cast<bool>(fo1) ); + VERIFY( fo1() == 1 ); + + fo = function(f2); + function fo2(std::move(fo)); + VERIFY( static_cast<bool>(fo2) ); + VERIFY( fo2() == 2 ); +} + +int main() +{ + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/cons/move_target.cc b/libstdc++-v3/testsuite/20_util/function/cons/move_target.cc new file mode 100644 index 000000000..2396ca101 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/cons/move_target.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// 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 <functional> + +struct moveable +{ + moveable() = default; + ~moveable() = default; + // target object must be CopyConstructible, + // but should not be copied during this test + moveable(const moveable& c) { throw "copied"; } + moveable& operator=(const moveable&) = delete; + moveable(moveable&&) { } + + void operator()() const { } +}; + +void test01() +{ + std::function<void ()> f = moveable(); + f(); +} + +int main() +{ + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/invoke/move_only.cc b/libstdc++-v3/testsuite/20_util/function/invoke/move_only.cc new file mode 100644 index 000000000..fbfb0624a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/invoke/move_only.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x" } + +// 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 <functional> + +struct moveable +{ + moveable() = default; + ~moveable() = default; + moveable(const moveable& c) = delete; + moveable& operator=(const moveable&) = delete; + moveable(moveable&&) { } +}; + +void f1(moveable) { } +void f2(moveable&&) { } +struct { void operator()(moveable&&) { } } f3; + +void test01() +{ + std::function<void (moveable)> fo1a(f1); + fo1a(moveable()); + + std::function<void (moveable)> fo2a(f2); + fo2a(moveable()); + + std::function<void (moveable)> fo3a(f3); + fo3a(moveable()); + + std::function<void (moveable&&)> fo1b(f1); + fo1b(moveable()); + + std::function<void (moveable&&)> fo2b(f2); + fo2b(moveable()); + + std::function<void (moveable&&)> fo3b(f3); + fo3b(moveable()); +} + +int main() +{ + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function/null_pointer_comparisons.cc b/libstdc++-v3/testsuite/20_util/function/null_pointer_comparisons.cc new file mode 100644 index 000000000..7f446d7d6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/null_pointer_comparisons.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <functional> + +// libstdc++/40273 +int main() +{ + std::function<void* ()> f = 0; + if (f != 0) + { + } + + if (0 != f) + { + } + + if (f == 0) + { + } + + if (0 == f) + { + } + return 0; +} + diff --git a/libstdc++-v3/testsuite/20_util/function/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/function/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..dbd8be630 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/requirements/explicit_instantiation.cc @@ -0,0 +1,26 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <functional> + +namespace std +{ + template class function<void* ()>; +} diff --git a/libstdc++-v3/testsuite/20_util/function_objects/binders/1.cc b/libstdc++-v3/testsuite/20_util/function_objects/binders/1.cc new file mode 100644 index 000000000..bbca92716 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/binders/1.cc @@ -0,0 +1,103 @@ +// Copyright (C) 2005, 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/>. + +// 20.3.6 Binders + +// { dg-do compile } + +#include <functional> +using namespace std; + +struct s +{ + void f_void_int_const(int) const {} + void f_void_int(int) {} + int f_int_int_const(int) const { return 1; } + int f_int_int(int) {return 1; } + void f_void_void_const() const {} + void f_void_void() {} + int f_int_void_const() const { return 1; } + int f_int_void() { return 1; } +}; + +void test01(s& a) +{ + mem_fun_t<void, s> p1(&s::f_void_void); + mem_fun_t<int, s> p2(&s::f_int_void); + p1(&a); + p2(&a); + mem_fun1_t<void, s, int> q1(&s::f_void_int); + mem_fun1_t<int, s, int> q2(&s::f_int_int); + q1(&a,0); + q2(&a,0); + + (mem_fun(&s::f_void_void))(&a); + (mem_fun(&s::f_void_int))(&a,0); + (mem_fun(&s::f_int_void))(&a); + (mem_fun(&s::f_int_int))(&a,0); + + mem_fun_ref_t<void, s> ref1(&s::f_void_void); + mem_fun_ref_t<int, s> ref2(&s::f_int_void); + + ref1(a); + ref2(a); + + mem_fun1_ref_t<void, s, int> ref3(&s::f_void_int); + mem_fun1_ref_t<int, s, int> ref4(&s::f_int_int); + + ref3(a,0); + ref4(a,0); + + (mem_fun_ref(&s::f_void_void))(a); + (mem_fun_ref(&s::f_void_int))(a, 0); + (mem_fun_ref(&s::f_int_void))(a); + (mem_fun_ref(&s::f_int_int))(a, 0); +} + +void test02(const s& a) +{ + const_mem_fun_t<void, s> p1(&s::f_void_void_const); + const_mem_fun_t<int, s> p2(&s::f_int_void_const); + p1(&a); + p2(&a); + const_mem_fun1_t<void, s, int> q1(&s::f_void_int_const); + const_mem_fun1_t<int, s, int> q2(&s::f_int_int_const); + q1(&a,0); + q2(&a,0); + + (mem_fun(&s::f_void_void_const))(&a); + (mem_fun(&s::f_void_int_const))(&a, 0); + (mem_fun(&s::f_int_void_const))(&a); + (mem_fun(&s::f_int_int_const))(&a, 0); + + const_mem_fun_ref_t<void, s> ref1(&s::f_void_void_const); + const_mem_fun_ref_t<int, s> ref2(&s::f_int_void_const); + + ref1(a); + ref2(a); + + const_mem_fun1_ref_t<void, s, int> ref3(&s::f_void_int_const); + const_mem_fun1_ref_t<int, s, int> ref4(&s::f_int_int_const); + + ref3(a,0); + ref4(a,0); + + (mem_fun_ref(&s::f_void_void_const))(a); + (mem_fun_ref(&s::f_void_int_const))(a, 0); + (mem_fun_ref(&s::f_int_void_const))(a); + (mem_fun_ref(&s::f_int_int_const))(a, 0); +} diff --git a/libstdc++-v3/testsuite/20_util/function_objects/binders/3113.cc b/libstdc++-v3/testsuite/20_util/function_objects/binders/3113.cc new file mode 100644 index 000000000..229e56a4d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/binders/3113.cc @@ -0,0 +1,49 @@ +// 2001-06-11 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003, 2004, 2005, 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/>. + +// 20.3.6 Binders + +#include <vector> +#include <algorithm> // for_each +#include <functional> + +class Elem +{ +public: + void print(int) const { } + void modify(int) { } +}; + +// libstdc++/3113 +void test01() +{ + std::vector<Elem> coll(2); + // OK + std::for_each(coll.begin(), coll.end(), + std::bind2nd(std::mem_fun_ref(&Elem::print), 42)); + // OK + std::for_each(coll.begin(), coll.end(), + std::bind2nd(std::mem_fun_ref(&Elem::modify), 42)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function_objects/comparisons.cc b/libstdc++-v3/testsuite/20_util/function_objects/comparisons.cc new file mode 100644 index 000000000..fbc7c63c1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/comparisons.cc @@ -0,0 +1,52 @@ +// 2001-06-18 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 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/>. + +// 20.3.3 Comparisons + +#include <functional> + +class gnu_obj +{ + int i; +public: + gnu_obj(int arg = 0): i(arg) { } + bool operator==(const gnu_obj& rhs) const { return i == rhs.i; } + bool operator!=(const gnu_obj& rhs) const { return i != rhs.i; } + bool operator<(const gnu_obj& rhs) const { return i < rhs.i; } +}; + +template<typename T> + struct gnu_t + { + bool b; + public: + gnu_t(bool arg = 0): b(arg) { } + bool operator==(const gnu_t& rhs) const { return b == rhs.b; } + bool operator!=(const gnu_t& rhs) const { return b != rhs.b; } + bool operator<(const gnu_t& rhs) const { return b == rhs.b; } + }; + +template struct std::not_equal_to<void*>; +template struct std::not_equal_to<gnu_obj>; +template struct std::not_equal_to<gnu_t<long> >; + +int main() +{ + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/function_objects/dr660.cc b/libstdc++-v3/testsuite/20_util/function_objects/dr660.cc new file mode 100644 index 000000000..d16542d15 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/dr660.cc @@ -0,0 +1,41 @@ +// 2007-08-02 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <functional> +#include <testsuite_hooks.cc> + +// DR 660. Missing Bitwise Operations. +void test01() +{ + bool test __attribute__((unused)) = true; + + for (int i1 = 0; i1 < 1000; ++i1) + for (int i2 = 0; i2 < 1000; ++i2) + { + VERIFY( std::bit_and<int>()(i1, i2) == (i1 & i2) ); + VERIFY( std::bit_or<int>()(i1, i2) == (i1 | i2) ); + VERIFY( std::bit_xor<int>()(i1, i2) == (i1 ^ i2) ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/has_nothrow_copy_assign/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_assign/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..0a4a6224b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_assign/requirements/explicit_instantiation.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2010-06-08 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct has_nothrow_copy_assign<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/has_nothrow_copy_assign/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_assign/requirements/typedefs.cc new file mode 100644 index 000000000..3781d1f9b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_assign/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2010-06-08 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::has_nothrow_copy_assign<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/has_nothrow_copy_assign/value.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_assign/value.cc new file mode 100644 index 000000000..0201c9cb9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_assign/value.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } +// 2010-06-08 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 <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::has_nothrow_copy_assign; + using namespace __gnu_test; + + VERIFY( (test_property<has_nothrow_copy_assign, int>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, float>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, EnumType>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, int*>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, int(*)(int)>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, int (ClassType::*)>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, + int (ClassType::*) (int)>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, int[2]>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, float[][3]>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, EnumType[2][3][4]>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, int*[3]>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, int(*[][2])(int)>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, + int (ClassType::*[2][3])>(true)) ); + VERIFY( (test_property<has_nothrow_copy_assign, + int (ClassType::*[][2][3]) (int)>(true)) ); + + // Negative tests. + VERIFY( (test_property<has_nothrow_copy_assign, void>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..7c8445150 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct has_nothrow_copy_constructor<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/requirements/typedefs.cc new file mode 100644 index 000000000..5c40837aa --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2004-12-30 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2004, 2007, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::has_nothrow_copy_constructor<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/has_nothrow_copy_constructor/value.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/value.cc new file mode 100644 index 000000000..963c7bd57 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/value.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++0x" } +// 2004-12-30 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2004, 2005, 2007, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::has_nothrow_copy_constructor; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_category<has_nothrow_copy_constructor, int>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, float>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, EnumType>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, int*>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, int(*)(int)>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, int (ClassType::*)>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, int (ClassType::*) (int)>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, int[2]>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, float[][3]>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, EnumType[2][3][4]>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, int*[3]>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, int(*[][2])(int)>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, int (ClassType::*[2][3])>(true)) ); + VERIFY( (test_category<has_nothrow_copy_constructor, + int (ClassType::*[][2][3]) (int)>(true)) ); + + // Negative tests. + VERIFY( (test_category<has_nothrow_copy_constructor, void>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..dec9b965e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct has_nothrow_default_constructor<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/requirements/typedefs.cc new file mode 100644 index 000000000..709fff331 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2004-12-29 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2004, 2007, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::has_nothrow_default_constructor<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/has_nothrow_default_constructor/value.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/value.cc new file mode 100644 index 000000000..01548211c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/value.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x" } +// 2004-12-29 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2004, 2005, 2006, 2007, 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/>. + +// 4.5.3 Type properties + +#include <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::has_nothrow_default_constructor; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_category<has_nothrow_default_constructor, int>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, float>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, EnumType>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, int*>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, int(*)(int)>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, int (ClassType::*)>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, + int (ClassType::*) (int)>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, int[2]>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, float[][3]>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, EnumType[2][3][4]>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, int*[3]>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, int(*[][2])(int)>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, + int (ClassType::*[2][3])>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, + int (ClassType::*[][2][3]) (int)>(true)) ); + VERIFY( (test_category<has_nothrow_default_constructor, ClassType>(true)) ); + + // Negative tests. + VERIFY( (test_category<has_nothrow_default_constructor, void>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/has_trivial_copy_assign/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/has_trivial_copy_assign/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..6ec5c5a42 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_trivial_copy_assign/requirements/explicit_instantiation.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2010-06-08 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct has_trivial_copy_assign<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/has_trivial_copy_assign/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/has_trivial_copy_assign/requirements/typedefs.cc new file mode 100644 index 000000000..1c5f0fe7a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_trivial_copy_assign/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2010-06-08 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::has_trivial_copy_assign<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/has_trivial_copy_assign/value.cc b/libstdc++-v3/testsuite/20_util/has_trivial_copy_assign/value.cc new file mode 100644 index 000000000..7663a688a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_trivial_copy_assign/value.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } +// 2010-06-08 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 <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::has_trivial_copy_assign; + using namespace __gnu_test; + + VERIFY( (test_property<has_trivial_copy_assign, int>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, float>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, EnumType>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, int*>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, int(*)(int)>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, int (ClassType::*)>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, + int (ClassType::*) (int)>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, int[2]>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, float[][3]>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, EnumType[2][3][4]>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, int*[3]>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, int(*[][2])(int)>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, + int (ClassType::*[2][3])>(true)) ); + VERIFY( (test_property<has_trivial_copy_assign, + int (ClassType::*[][2][3]) (int)>(true)) ); + + // Negative tests. + VERIFY( (test_property<has_trivial_copy_assign, void>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..6377f60a8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct has_trivial_copy_constructor<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/requirements/typedefs.cc new file mode 100644 index 000000000..4b0013f7f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2004-12-30 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2004, 2007, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::has_trivial_copy_constructor<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/has_trivial_copy_constructor/value.cc b/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/value.cc new file mode 100644 index 000000000..4f6e287b5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/value.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++0x" } +// 2004-12-30 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2004, 2005, 2007, 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/>. + +// 4.5.3 Type properties + +#include <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::has_trivial_copy_constructor; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_category<has_trivial_copy_constructor, int>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, float>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, EnumType>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, int*>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, int(*)(int)>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, int (ClassType::*)>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, int (ClassType::*) (int)>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, int[2]>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, float[][3]>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, EnumType[2][3][4]>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, int*[3]>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, int(*[][2])(int)>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, int (ClassType::*[2][3])>(true)) ); + VERIFY( (test_category<has_trivial_copy_constructor, + int (ClassType::*[][2][3]) (int)>(true)) ); + + // Negative tests. + VERIFY( (test_category<has_trivial_copy_constructor, void>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..2d98181d9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct has_trivial_default_constructor<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/requirements/typedefs.cc new file mode 100644 index 000000000..40f38c34a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2004-12-26 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2004, 2007, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::has_trivial_default_constructor<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/has_trivial_default_constructor/value.cc b/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/value.cc new file mode 100644 index 000000000..397149406 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/value.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x" } +// 2004-12-26 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2004, 2005, 2006, 2007, 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/>. + +// 4.5.3 Type properties + +#include <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::has_trivial_default_constructor; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_category<has_trivial_default_constructor, int>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, float>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, EnumType>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, int*>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, int(*)(int)>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, int (ClassType::*)>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, + int (ClassType::*) (int)>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, int[2]>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, float[][3]>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, EnumType[2][3][4]>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, int*[3]>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, int(*[][2])(int)>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, + int (ClassType::*[2][3])>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, + int (ClassType::*[][2][3]) (int)>(true)) ); + VERIFY( (test_category<has_trivial_default_constructor, ClassType>(true)) ); + + // Negative tests. + VERIFY( (test_category<has_trivial_default_constructor, void>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/hash/chi2_quality.cc b/libstdc++-v3/testsuite/20_util/hash/chi2_quality.cc new file mode 100644 index 000000000..8a388349b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/hash/chi2_quality.cc @@ -0,0 +1,218 @@ +// { dg-options "-std=gnu++0x" } + +// Use smaller statistics when running on simulators, so it takes less time. +// { dg-options "-std=gnu++0x -DSAMPLES=10000" { target simulator } } + +// Copyright (C) 2010, 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/>. + +// This file uses the chi^2 test to measure the quality of a hash +// function, by computing the uniformity with which it distributes a set +// of N strings into k buckets (where k is significantly greater than N). +// +// Each bucket has B[i] strings in it. The expected value of each bucket +// for a uniform distribution is z = N/k, so +// chi^2 = Sum_i (B[i] - z)^2 / z. +// +// We check whether chi^2 is small enough to be consistent with the +// hypothesis of a uniform distribution. If F(chi^2, k-1) is close to +// 0 (where F is the cumulative probability distribution), we can +// reject that hypothesis. So we don't want F to be too small, which +// for large k, means we want chi^2 to be not too much larger than k. +// +// We use the chi^2 test for several sets of strings. Any non-horrible +// hash function should do well with purely random strings. A really +// good hash function will also do well with more structured sets, +// including ones where the strings differ by only a few bits. + +#include <algorithm> +#include <cstdlib> +#include <cstdio> +#include <fstream> +#include <functional> +#include <iostream> +#include <iterator> +#include <string> +#include <unordered_set> +#include <vector> +#include <testsuite_hooks.h> + +#ifndef SAMPLES +#define SAMPLES 300000 +#endif + +template <typename Container> + double + chi2_hash(const Container& c, long buckets) + { + std::vector<int> counts(buckets); + std::hash<std::string> hasher; + double elements = 0; + for (auto i = c.begin(); i != c.end(); ++i) + { + ++counts[hasher(*i) % buckets]; + ++elements; + } + + const double z = elements / buckets; + double sum = 0; + for (long i = 0; i < buckets; ++i) + { + double delta = counts[i] - z; + sum += delta*delta; + } + return sum/z; + } + +// Tests chi^2 for a distribution of uniformly generated random strings. +void +test_uniform_random() +{ + bool test __attribute__((unused)) = true; + std::srand(137); + std::unordered_set<std::string> set; + std::string s; + const unsigned long N = SAMPLES; + const unsigned long k = N/100; + const unsigned int len = 25; + while (set.size() < N) + { + s.clear(); + for (unsigned int i = 0; i < len; ++i) + s.push_back(rand() % 128); + set.insert(s); + } + + double chi2 = chi2_hash(set, k); + VERIFY( chi2 < k*1.1 ); +} + +// Tests chi^2 for a distribution of strings that differ from each +// other by only a few bits. We start with an arbitrary base string, and +// flip three random bits for each member of the set. +void +test_bit_flip_set() +{ + bool test __attribute__((unused)) = true; + const unsigned long N = SAMPLES; + const unsigned long k = N/100; + const unsigned int len = 67; + const unsigned int bitlen = len * 8; + const unsigned int bits_to_flip = 3; + const char base[len+1] = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789!@#$%"; + + std::unordered_set<std::string> set; + while (set.size() < N) + { + std::string s(base, base+len); + for (unsigned int i = 0; i < bits_to_flip; ++i) + { + int bit = rand() % bitlen; + s[bit/8] ^= (1 << (bit%8)); + } + set.insert(s); + } + + double chi2 = chi2_hash(set, k); + VERIFY( chi2 < k*1.1 ); +} + +// Tests chi^2 of a set of strings that all have a similar pattern, +// intended to mimic some sort of ID string. +void +test_numeric_pattern_set() +{ + bool test __attribute__((unused)) = true; + const unsigned long N = SAMPLES; + const unsigned long k = N/100; + std::vector<std::string> set; + for (unsigned long i = 0; i < N; ++i) + { + long i1 = i % 100000; + long i2 = i / 100000; + char buf[16]; + std::sprintf(buf, "XX-%05lu-%05lu", i1, i2); + set.push_back(buf); + } + + double chi2 = chi2_hash(set, k); + VERIFY( chi2 < k*1.1 ); +} + +// Tests chi^2 for a set of strings that all consist of '1' and '0'. +void +test_bit_string_set() +{ + bool test __attribute__((unused)) = true; + const unsigned long N = SAMPLES; + const unsigned long k = N/100; + std::vector<std::string> set; + std::string s; + for (unsigned long i = 0; i < N; ++i) + { + s.clear(); + for (unsigned int j = 0; j < sizeof(unsigned long) * 8; ++j) + { + const bool bit = (1UL << j) & i; + s.push_back(bit ? '1' : '0'); + } + set.push_back(s); + } + + double chi2 = chi2_hash(set, k); + VERIFY( chi2 < k*1.1 ); +} + +// Tests chi^2 for a set of words taken from a document written in English. +void +test_document_words() +{ + // That file is 187587 single-word lines. To avoid a timeout, just skip + // this part, which would take up to 95% of the program runtime (with + // SAMPLES == 10000), if we're not supposed to run anywhere that long. +#if SAMPLES >= 100000 + bool test __attribute__((unused)) = true; + const std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + std::ifstream in(f_name); + VERIFY( in.is_open() ); + std::vector<std::string> words; + words.assign(std::istream_iterator<std::string>(in), + std::istream_iterator<std::string>()); + VERIFY( words.size() > 100000 ); + std::sort(words.begin(), words.end()); + auto it = std::unique(words.begin(), words.end()); + words.erase(it, words.end()); + VERIFY( words.size() > 5000 ); + + const unsigned long k = words.size() / 20; + double chi2 = chi2_hash(words, k); + VERIFY( chi2 < k*1.1 ); +#endif +} + +int +main() +{ + test_uniform_random(); + test_bit_flip_set(); + test_numeric_pattern_set(); + test_bit_string_set(); + test_document_words(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc b/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc new file mode 100644 index 000000000..af0c54ec4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++0x" } +// 2007-08-20 <benjamin@redhat.com> +// +// Copyright (C) 2007, 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 <functional> +#include <system_error> +#include <testsuite_hooks.h> + +template<typename T> + void + do_test() + { + bool test __attribute__((unused)) = true; + + typedef T value_type; + typedef std::hash<value_type> hash_type; + using std::size_t; + + value_type v; // default initialized is fine, same value all that matters. + hash_type h1; + size_t r1 = size_t(h1(v)); + + hash_type h2; + size_t r2 = size_t(h2(v)); + + VERIFY( r1 == r2 ); + } + +void test01() +{ + do_test<std::error_code>(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/hash/quality.cc b/libstdc++-v3/testsuite/20_util/hash/quality.cc new file mode 100644 index 000000000..0bc263724 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/hash/quality.cc @@ -0,0 +1,172 @@ +// { dg-options "-std=gnu++0x" } +// { dg-options "-DNTESTS=1 -DNSTRINGS=100 -DSTRSIZE=21 -std=gnu++0x" { target simulator } } + +// Copyright (C) 2010, 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/>. + +#include <cstdlib> +#include <unordered_set> +#include <string> +#include <functional> +#include <vector> +#include <testsuite_hooks.h> + +using namespace std; + +#ifndef NTESTS +#define NTESTS 5 +#endif +#ifndef NSTRINGS +#define NSTRINGS 200 +#endif +#ifndef STRSIZE +#define STRSIZE 42 +#endif + +const unsigned int num_quality_tests = NTESTS; +const unsigned int num_strings_for_quality_tests = NSTRINGS; +const unsigned int string_size = STRSIZE; + +vector<string> +random_strings(unsigned int n, unsigned int len) +{ + string s(len, '\0'); + unordered_set<string> result_set; + while (result_set.size() < n) + { + result_set.insert(s); + unsigned int tmp = rand(); + tmp %= len * 256; + s[tmp / 256] = tmp % 256; + } + return vector<string>(result_set.begin(), result_set.end()); +} + +double +score_from_varying_position(string s, unsigned int index) +{ + bool test __attribute__((unused)) = true; + unsigned int bits_in_hash_code = sizeof(size_t) * 8; + + // We'll iterate through all 256 vals for s[index], leaving the rest + // of s fixed. Then, for example, out of the 128 times that + // s[index] has its 3rd bit equal to 0 we would like roughly half 1s + // and half 0s in bit 9 of the hash codes. + // + // Bookkeeping: Conceptually we want a 3D array of ints. We want to + // count the number of times each output position (of which there are + // bits_in_hash_code) is 1 for each bit position within s[index] (of + // which there are 8) and value of that bit (of which there are 2). + const unsigned int jj = 2; + const unsigned int kk = jj * bits_in_hash_code; + const unsigned int array_size = 8 * kk; + vector<int> ones(array_size, 0); + + for (int i = 0; i < 256; i++) + { + s[index] = i; + size_t h = hash<string>()(s); + for (int j = 0; h != 0; j++, h >>= 1) + { + if (h & 1) + { + for (int k = 0; k < 8; k++) + ++ones[k * kk + j * jj + ((i >> k) & 1)]; + } + } + } + + // At most, the innermost statement in the above loop nest can + // execute 256 * bits_in_hash_code * 8 times. If the hash is good, + // it'll execute about half that many times, with a pretty even + // spread across the elements of ones[]. + VERIFY( 256 * bits_in_hash_code * 8 / array_size == 128 ); + int max_ones_possible = 128; + int good = 0, bad = 0; + for (int bit = 0; bit <= 1; bit++) + { + for (unsigned int j = 0; j < bits_in_hash_code; j++) + { + for (int bitpos = 0; bitpos < 8; bitpos++) + { + int z = ones[bitpos * kk + j * jj + bit]; + if (z <= max_ones_possible / 6 + || z >= max_ones_possible * 5 / 6) + { + // The hash function screwed up, or was just unlucky, + // as 128 flips of a perfect coin occasionally yield + // far from 64 heads. + bad++; + } + else + good++; + } + } + } + return good / (double)(good + bad); +} + +double +score_from_varying_position(const vector<string>& v, unsigned int index) +{ + double score = 0; + for (unsigned int i = 0; i < v.size(); i++) + score += score_from_varying_position(v[i], index); + return score / v.size(); +} + +double +quality_test(unsigned int num_strings, unsigned int string_size) +{ + // Construct random strings. + vector<string> v = random_strings(num_strings, string_size); + double sum_of_scores = 0; + for (unsigned int i = 0; i < string_size; i++) + sum_of_scores += score_from_varying_position(v, i); + + // A good hash function should have a score very close to 1, and a bad + // hash function will have a score close to 0. + return sum_of_scores / string_size; +} + +void +quality_test() +{ + bool test __attribute__((unused)) = true; + srand(137); + double sum_of_scores = 0; + for (unsigned int i = 0; i < num_quality_tests; i++) + { + double score = quality_test(num_strings_for_quality_tests, + string_size); + sum_of_scores += score; + VERIFY( score > 0.99 ); + } + + if (num_quality_tests > 1) + { + double mean_quality = sum_of_scores / num_quality_tests; + VERIFY( mean_quality > 0.9999 ); + } +} + +int +main() +{ + quality_test(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..9c71a5fc9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 2008, 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 <functional> +#include <string> +#include <system_error> + +// Verify that we can instantiate hash for every required type. +template class std::hash<bool>; +template class std::hash<char>; +template class std::hash<signed char>; +template class std::hash<unsigned char>; +template class std::hash<char16_t>; +template class std::hash<char32_t>; +template class std::hash<short>; +template class std::hash<int>; +template class std::hash<long>; +template class std::hash<unsigned short>; +template class std::hash<unsigned int>; +template class std::hash<unsigned long>; +template class std::hash<float>; +template class std::hash<double>; +template class std::hash<long double>; +template class std::hash<void*>; +template class std::hash<std::string>; +template class std::hash<std::error_code>; + +#ifdef _GLIBCXX_USE_WCHAR_T +template class std::hash<wchar_t>; +template class std::hash<std::wstring>; +#endif + diff --git a/libstdc++-v3/testsuite/20_util/headers/cstdlib/functions_std.cc b/libstdc++-v3/testsuite/20_util/headers/cstdlib/functions_std.cc new file mode 100644 index 000000000..ad25a7f5e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/cstdlib/functions_std.cc @@ -0,0 +1,28 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <cstdlib> + +namespace gnu +{ + using std::calloc; + using std::malloc; + using std::free; + using std::realloc; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/cstring/functions_std.cc b/libstdc++-v3/testsuite/20_util/headers/cstring/functions_std.cc new file mode 100644 index 000000000..34bc2b945 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/cstring/functions_std.cc @@ -0,0 +1,29 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <cstring> + +namespace gnu +{ + using std::memchr; + using std::memcmp; + using std::memcpy; + using std::memmove; + using std::memset; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/cstring/macros.cc b/libstdc++-v3/testsuite/20_util/headers/cstring/macros.cc new file mode 100644 index 000000000..d85767dd5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/cstring/macros.cc @@ -0,0 +1,27 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <cstring> + +namespace gnu +{ +#ifndef NULL + #error "NULL_must_be_a_macro" +#endif +} diff --git a/libstdc++-v3/testsuite/20_util/headers/cstring/types_std.cc b/libstdc++-v3/testsuite/20_util/headers/cstring/types_std.cc new file mode 100644 index 000000000..306d2547b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/cstring/types_std.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <cstring> + +namespace gnu +{ + std::size_t s; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/ctime/functions_std.cc b/libstdc++-v3/testsuite/20_util/headers/ctime/functions_std.cc new file mode 100644 index 000000000..baba33fc8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/ctime/functions_std.cc @@ -0,0 +1,33 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <ctime> + +namespace gnu +{ + using std::asctime; + using std::clock; + using std::difftime; + using std::localtime; + using std::strftime; + using std::ctime; + using std::gmtime; + using std::mktime; + using std::time; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/ctime/macros.cc b/libstdc++-v3/testsuite/20_util/headers/ctime/macros.cc new file mode 100644 index 000000000..0633aa2f8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/ctime/macros.cc @@ -0,0 +1,27 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <ctime> + +namespace gnu +{ +#ifndef NULL + #error "NULL_must_be_a_macro" +#endif +} diff --git a/libstdc++-v3/testsuite/20_util/headers/ctime/types_std.cc b/libstdc++-v3/testsuite/20_util/headers/ctime/types_std.cc new file mode 100644 index 000000000..db7bb7ff1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/ctime/types_std.cc @@ -0,0 +1,29 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <ctime> + +namespace gnu +{ + std::size_t s; + std::clock_t c; + std::time_t t; + + std::tm t2; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/functional/synopsis.cc b/libstdc++-v3/testsuite/20_util/headers/functional/synopsis.cc new file mode 100644 index 000000000..b58314466 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/functional/synopsis.cc @@ -0,0 +1,100 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <functional> + +namespace std { + // lib.base, base: + template <class Arg, class Result> struct unary_function; + template <class Arg1, class Arg2, class Result> struct binary_function; + + // lib.arithmetic.operations, arithmetic operations: + template <class T> struct plus; + template <class T> struct minus; + template <class T> struct multiplies; + template <class T> struct divides; + template <class T> struct modulus; + template <class T> struct negate; + + // lib.comparisons, comparisons: + template <class T> struct equal_to; + template <class T> struct not_equal_to; + template <class T> struct greater; + template <class T> struct less; + template <class T> struct greater_equal; + template <class T> struct less_equal; + + // lib.logical.operations, logical operations: + template <class T> struct logical_and; + template <class T> struct logical_or; + template <class T> struct logical_not; + + // lib.negators, negators: + template <class Predicate> struct unary_negate; + template <class Predicate> + unary_negate<Predicate> not1(const Predicate&); + template <class Predicate> struct binary_negate; + template <class Predicate> + binary_negate<Predicate> not2(const Predicate&); + + // lib.binders, binders: + template <class Operation> class binder1st; + template <class Operation, class T> + binder1st<Operation> bind1st(const Operation&, const T&); + template <class Operation> class binder2nd; + template <class Operation, class T> + binder2nd<Operation> bind2nd(const Operation&, const T&); + + // lib.function.pointer.adaptors, adaptors: + template <class Arg, class Result> class pointer_to_unary_function; + template <class Arg, class Result> + pointer_to_unary_function<Arg,Result> ptr_fun(Result (*)(Arg)); + template <class Arg1, class Arg2, class Result> + class pointer_to_binary_function; + template <class Arg1, class Arg2, class Result> + pointer_to_binary_function<Arg1,Arg2,Result> + ptr_fun(Result (*)(Arg1,Arg2)); + + // lib.member.pointer.adaptors, adaptors: + template<class S, class T> class mem_fun_t; + template<class S, class T, class A> class mem_fun1_t; + template<class S, class T> + mem_fun_t<S,T> mem_fun(S (T::*f)()); + template<class S, class T, class A> + mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); + template<class S, class T> class mem_fun_ref_t; + template<class S, class T, class A> class mem_fun1_ref_t; + template<class S, class T> + mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); + template<class S, class T, class A> + mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); + + template <class S, class T> class const_mem_fun_t; + template <class S, class T, class A> class const_mem_fun1_t; + template <class S, class T> + const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); + template <class S, class T, class A> + const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); + template <class S, class T> class const_mem_fun_ref_t; + template <class S, class T, class A> class const_mem_fun1_ref_t; + template <class S, class T> + const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); + template <class S, class T, class A> + const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); +} diff --git a/libstdc++-v3/testsuite/20_util/headers/functional/types_std_c++0x.cc b/libstdc++-v3/testsuite/20_util/headers/functional/types_std_c++0x.cc new file mode 100644 index 000000000..264542811 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/functional/types_std_c++0x.cc @@ -0,0 +1,26 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <functional> + +namespace gnu +{ + using std::bad_function_call; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/functional/using_namespace_std_placeholders.cc b/libstdc++-v3/testsuite/20_util/headers/functional/using_namespace_std_placeholders.cc new file mode 100644 index 000000000..5d2a7a863 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/functional/using_namespace_std_placeholders.cc @@ -0,0 +1,26 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <functional> + +namespace gnu +{ + using namespace std::placeholders; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/memory/synopsis.cc b/libstdc++-v3/testsuite/20_util/headers/memory/synopsis.cc new file mode 100644 index 000000000..4d45071e6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/memory/synopsis.cc @@ -0,0 +1,53 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <memory> + +namespace std { + // lib.default.allocator, the default allocator: + template <class T> class allocator; + template <> class allocator<void>; + template <class T, class U> + bool operator==(const allocator<T>&, const allocator<U>&) throw(); + template <class T, class U> + bool operator!=(const allocator<T>&, const allocator<U>&) throw(); + + // lib.storage.iterator, raw storage iterator: + template <class OutputIterator, class T> class raw_storage_iterator; + + // lib.temporary.buffer, temporary buffers: + template <class T> + pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n); + template <class T> + void return_temporary_buffer(T* p); + + // lib.specialized.algorithms, specialized algorithms: + template <class InputIterator, class ForwardIterator> + ForwardIterator + uninitialized_copy(InputIterator first, InputIterator last, + ForwardIterator result); + template <class ForwardIterator, class T> + void uninitialized_fill(ForwardIterator first, ForwardIterator last, + const T& x); + template <class ForwardIterator, class Size, class T> + void uninitialized_fill_n(ForwardIterator first, Size n, const T& x); + + // lib.auto.ptr, pointers: + template<class X> class auto_ptr; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/memory/types_std_c++0x.cc b/libstdc++-v3/testsuite/20_util/headers/memory/types_std_c++0x.cc new file mode 100644 index 000000000..dc50b63bb --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/memory/types_std_c++0x.cc @@ -0,0 +1,26 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <memory> + +namespace gnu +{ + using std::bad_weak_ptr; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/type_traits/std_c++0x_neg.cc b/libstdc++-v3/testsuite/20_util/headers/type_traits/std_c++0x_neg.cc new file mode 100644 index 000000000..4fd554e35 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/type_traits/std_c++0x_neg.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +// Copyright (C) 2007, 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> + +// { dg-error "upcoming ISO" "" { target *-*-* } 32 } + + + diff --git a/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x.cc b/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x.cc new file mode 100644 index 000000000..0fc1ce295 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x.cc @@ -0,0 +1,27 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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> + +namespace gnu +{ + using std::true_type; + using std::false_type; +} diff --git a/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x_neg.cc b/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x_neg.cc new file mode 100644 index 000000000..5ada352ec --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x_neg.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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> + +namespace gnu +{ + // C++0x changes from TR1. + using std::has_trivial_constructor; + using std::has_nothrow_constructor; + using std::has_trivial_copy; + using std::has_nothrow_copy; +} + +// { dg-error "has not been declared" "" { target *-*-* } 26 } +// { dg-error "has not been declared" "" { target *-*-* } 27 } +// { dg-error "has not been declared" "" { target *-*-* } 28 } +// { dg-error "has not been declared" "" { target *-*-* } 29 } + diff --git a/libstdc++-v3/testsuite/20_util/headers/utility/synopsis.cc b/libstdc++-v3/testsuite/20_util/headers/utility/synopsis.cc new file mode 100644 index 000000000..aea7bb3bf --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/utility/synopsis.cc @@ -0,0 +1,45 @@ +// { dg-do compile } + +// Copyright (C) 2007, 2008, 2009, 2010, 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/>. + +#include <utility> + +namespace std { + // lib.operators, operators: + namespace rel_ops { + template<class T> bool operator!=(const T&, const T&); + template<class T> bool operator> (const T&, const T&); + template<class T> bool operator<=(const T&, const T&); + template<class T> bool operator>=(const T&, const T&); + } + + // lib.pairs, pairs: + template <class T1, class T2> struct pair; + template <class T1, class T2> + _GLIBCXX_CONSTEXPR bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); + template <class T1, class T2> + _GLIBCXX_CONSTEXPR bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); + template <class T1, class T2> + _GLIBCXX_CONSTEXPR bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); + template <class T1, class T2> + _GLIBCXX_CONSTEXPR bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); + template <class T1, class T2> + _GLIBCXX_CONSTEXPR bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); + template <class T1, class T2> + _GLIBCXX_CONSTEXPR bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); +} diff --git a/libstdc++-v3/testsuite/20_util/headers/utility/using_namespace_std_rel_ops.cc b/libstdc++-v3/testsuite/20_util/headers/utility/using_namespace_std_rel_ops.cc new file mode 100644 index 000000000..60753a00f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/utility/using_namespace_std_rel_ops.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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> + +namespace gnu +{ + using namespace std::rel_ops; +} diff --git a/libstdc++-v3/testsuite/20_util/is_constructible/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_constructible/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..356f73cac --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_constructible/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2009-12-30 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_constructible<test_type, test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_constructible/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_constructible/requirements/typedefs.cc new file mode 100644 index 000000000..4b9ecd9e1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_constructible/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2009-12-30 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +void test01() +{ + // Check for required typedefs + typedef std::is_constructible<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/is_constructible/value.cc b/libstdc++-v3/testsuite/20_util/is_constructible/value.cc new file mode 100644 index 000000000..280710beb --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_constructible/value.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } + +// 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_constructible; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_property<is_constructible, ExplicitClass, double&>(true)) ); + VERIFY( (test_property<is_constructible, ExplicitClass, int&>(true)) ); + + // Negative tests. + VERIFY( (test_property<is_constructible, ExplicitClass, void*>(false)) ); + VERIFY( (test_property<is_constructible, ExplicitClass>(false)) ); + VERIFY( (test_property<is_constructible, ExplicitClass, + int, double>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_convertible/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_convertible/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..646c4b25b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_convertible/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2009-10-29 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_convertible<test_type, test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_convertible/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_convertible/requirements/typedefs.cc new file mode 100644 index 000000000..1e8deb511 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_convertible/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2009-10-29 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +void test01() +{ + // Check for required typedefs + typedef std::is_convertible<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/is_convertible/value.cc b/libstdc++-v3/testsuite/20_util/is_convertible/value.cc new file mode 100644 index 000000000..f6282a901 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_convertible/value.cc @@ -0,0 +1,106 @@ +// { dg-options "-std=gnu++0x" } + +// 2009-10-29 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_convertible; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_relationship<is_convertible, int, int>(true)) ); + VERIFY( (test_relationship<is_convertible, int, const int>(true)) ); + VERIFY( (test_relationship<is_convertible, volatile int, const int>(true)) ); + VERIFY( (test_relationship<is_convertible, int, float>(true)) ); + VERIFY( (test_relationship<is_convertible, double, float>(true)) ); + VERIFY( (test_relationship<is_convertible, float, int>(true)) ); + VERIFY( (test_relationship<is_convertible, int*, const int*>(true)) ); + VERIFY( (test_relationship<is_convertible, int*, void*>(true)) ); + VERIFY( (test_relationship<is_convertible, int[4], int*>(true)) ); + VERIFY( (test_relationship<is_convertible, float&, int>(true)) ); + VERIFY( (test_relationship<is_convertible, int, const int&>(true)) ); + VERIFY( (test_relationship<is_convertible, const int&, int>(true)) ); + VERIFY( (test_relationship<is_convertible, float, const int&>(true)) ); + VERIFY( (test_relationship<is_convertible, int(int), int(*)(int)>(true)) ); + VERIFY( (test_relationship<is_convertible, int(&)(int), int(*)(int)>(true)) ); + VERIFY( (test_relationship<is_convertible, EnumType, int>(true)) ); + VERIFY( (test_relationship<is_convertible, ClassType, ClassType>(true)) ); + VERIFY( (test_relationship<is_convertible, DerivedType, ClassType>(true)) ); + VERIFY( (test_relationship<is_convertible, DerivedType*, ClassType*>(true)) ); + VERIFY( (test_relationship<is_convertible, DerivedType&, ClassType&>(true)) ); + + VERIFY( (test_relationship<is_convertible, const int, const int&>(true)) ); + + VERIFY( (test_relationship<is_convertible, void, void>(true)) ); + VERIFY( (test_relationship<is_convertible, const void, void>(true)) ); + VERIFY( (test_relationship<is_convertible, void, volatile void>(true)) ); + VERIFY( (test_relationship<is_convertible, double&, ExplicitClass>(true)) ); + + // Negative tests. + VERIFY( (test_relationship<is_convertible, const int*, int*>(false)) ); + VERIFY( (test_relationship<is_convertible, int*, float*>(false)) ); + VERIFY( (test_relationship<is_convertible, const int[4], int*>(false)) ); + VERIFY( (test_relationship<is_convertible, int[4], int[4]>(false)) ); + VERIFY( (test_relationship<is_convertible, const int&, int&>(false)) ); + VERIFY( (test_relationship<is_convertible, float&, int&>(false)) ); + VERIFY( (test_relationship<is_convertible, float, volatile int&>(false)) ); + VERIFY( (test_relationship<is_convertible, int(int), int(int)>(false)) ); + VERIFY( (test_relationship<is_convertible, int(int), int(*)(void)>(false)) ); + VERIFY( (test_relationship<is_convertible, int(*)(int), + int(&)(int)>(false)) ); + VERIFY( (test_relationship<is_convertible, int, EnumType>(false)) ); + VERIFY( (test_relationship<is_convertible, int, ClassType>(false)) ); + VERIFY( (test_relationship<is_convertible, ClassType, DerivedType>(false)) ); + VERIFY( (test_relationship<is_convertible, ClassType*, + DerivedType*>(false)) ); + VERIFY( (test_relationship<is_convertible, ClassType&, + DerivedType&>(false)) ); + + VERIFY( (test_relationship<is_convertible, void, int>(false)) ); + VERIFY( (test_relationship<is_convertible, void, float>(false)) ); + VERIFY( (test_relationship<is_convertible, void, int(*)(int)>(false)) ); + + // C++0x + VERIFY( (test_relationship<is_convertible, int, void>(false)) ); + VERIFY( (test_relationship<is_convertible, int[4], void>(false)) ); + + VERIFY( (test_relationship<is_convertible, int, int&>(false)) ); + VERIFY( (test_relationship<is_convertible, float, + volatile float&>(false)) ); + VERIFY( (test_relationship<is_convertible, const volatile int, + const volatile int&>(false)) ); + VERIFY( (test_relationship<is_convertible, volatile int, + volatile int&>(false)) ); + VERIFY( (test_relationship<is_convertible, int(int), int(&)(int)>(false)) ); + + VERIFY( (test_relationship<is_convertible, int&, ExplicitClass>(false)) ); + VERIFY( (test_relationship<is_convertible, void*, ExplicitClass>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_explicitly_convertible/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_explicitly_convertible/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..87dd950b2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_explicitly_convertible/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2009-12-30 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_explicitly_convertible<test_type, test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_explicitly_convertible/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_explicitly_convertible/requirements/typedefs.cc new file mode 100644 index 000000000..52ba964b1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_explicitly_convertible/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2009-12-30 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +void test01() +{ + // Check for required typedefs + typedef std::is_explicitly_convertible<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/is_explicitly_convertible/value.cc b/libstdc++-v3/testsuite/20_util/is_explicitly_convertible/value.cc new file mode 100644 index 000000000..7e7048732 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_explicitly_convertible/value.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } + +// 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_explicitly_convertible; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_relationship<is_explicitly_convertible, double&, + ExplicitClass>(true)) ); + VERIFY( (test_relationship<is_explicitly_convertible, int&, + ExplicitClass>(true)) ); + + // Negative tests. + VERIFY( (test_relationship<is_explicitly_convertible, void*, + ExplicitClass>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_integral/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_integral/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..a294d097b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_integral/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2008-05-20 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_integral<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_integral/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_integral/requirements/typedefs.cc new file mode 100644 index 000000000..43bac85ee --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_integral/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2008-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2008, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_integral<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/is_integral/value.cc b/libstdc++-v3/testsuite/20_util/is_integral/value.cc new file mode 100644 index 000000000..6b1717b38 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_integral/value.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } +// 2008-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2008, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_integral; + using namespace __gnu_test; + + VERIFY( (test_category<is_integral, void>(false)) ); + + VERIFY( (test_category<is_integral, char>(true)) ); + VERIFY( (test_category<is_integral, signed char>(true)) ); + VERIFY( (test_category<is_integral, unsigned char>(true)) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( (test_category<is_integral, wchar_t>(true)) ); +#endif + VERIFY( (test_category<is_integral, char16_t>(true)) ); + VERIFY( (test_category<is_integral, char32_t>(true)) ); + VERIFY( (test_category<is_integral, short>(true)) ); + VERIFY( (test_category<is_integral, unsigned short>(true)) ); + VERIFY( (test_category<is_integral, int>(true)) ); + VERIFY( (test_category<is_integral, unsigned int>(true)) ); + VERIFY( (test_category<is_integral, long>(true)) ); + VERIFY( (test_category<is_integral, unsigned long>(true)) ); + VERIFY( (test_category<is_integral, long long>(true)) ); + VERIFY( (test_category<is_integral, unsigned long long>(true)) ); + + VERIFY( (test_category<is_integral, float>(false)) ); + VERIFY( (test_category<is_integral, double>(false)) ); + VERIFY( (test_category<is_integral, long double>(false)) ); + + // Sanity check. + VERIFY( (test_category<is_integral, ClassType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_literal_type/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_literal_type/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..6669a1e89 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_literal_type/requirements/explicit_instantiation.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2010-02-21 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_literal_type<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_literal_type/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_literal_type/requirements/typedefs.cc new file mode 100644 index 000000000..25bc88f29 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_literal_type/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2010-02-21 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_literal_type<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/is_literal_type/value.cc b/libstdc++-v3/testsuite/20_util/is_literal_type/value.cc new file mode 100644 index 000000000..77a6902b7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_literal_type/value.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-23 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 <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_literal_type; + using namespace __gnu_test; + + VERIFY( (test_category<is_literal_type, int>(true)) ); + VERIFY( (test_category<is_literal_type, unsigned char>(true)) ); + + VERIFY( (test_category<is_literal_type, TType>(true)) ); + VERIFY( (test_category<is_literal_type, PODType>(true)) ); + + VERIFY( (test_category<is_literal_type, NType>(false)) ); + VERIFY( (test_category<is_literal_type, SLType>(false)) ); + + VERIFY( (test_category<is_literal_type, LType>(true)) ); + VERIFY( (test_category<is_literal_type, LType[5]>(true)) ); + + VERIFY( (test_category<is_literal_type, NLType>(false)) ); + VERIFY( (test_category<is_literal_type, NLType[5]>(false)) ); + + VERIFY( (test_category<is_literal_type, LTypeDerived>(true)) ); + VERIFY( (test_category<is_literal_type, LTypeDerived[5]>(true)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_lvalue_reference/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_lvalue_reference/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..09ae91219 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_lvalue_reference/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_lvalue_reference<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_lvalue_reference/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_lvalue_reference/requirements/typedefs.cc new file mode 100644 index 000000000..348b59936 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_lvalue_reference/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_lvalue_reference<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/is_lvalue_reference/value.cc b/libstdc++-v3/testsuite/20_util/is_lvalue_reference/value.cc new file mode 100644 index 000000000..f57713585 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_lvalue_reference/value.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_lvalue_reference; + using namespace __gnu_test; + + VERIFY( (test_category<is_lvalue_reference, int&>(true)) ); + VERIFY( (test_category<is_lvalue_reference, ClassType&>(true)) ); + VERIFY( (test_category<is_lvalue_reference, int(&)(int)>(true)) ); + + // Sanity check. + VERIFY( (test_category<is_lvalue_reference, int&&>(false)) ); + VERIFY( (test_category<is_lvalue_reference, ClassType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..37ba9eb8b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-06-09 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_nothrow_constructible<test_type, test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc new file mode 100644 index 000000000..53a64a78f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-06-09 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +void test01() +{ + // Check for required typedefs + typedef std::is_nothrow_constructible<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/is_nothrow_constructible/value.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/value.cc new file mode 100644 index 000000000..b3246fad1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/value.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-09 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 <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_nothrow_constructible; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_property<is_nothrow_constructible, NoexceptExplicitClass, + double&>(true)) ); + VERIFY( (test_property<is_nothrow_constructible, NoexceptExplicitClass, + int&>(true)) ); + VERIFY( (test_property<is_nothrow_constructible, NoexceptExplicitClass, + double&, int&, double&>(true)) ); + VERIFY( (test_property<is_nothrow_constructible, NothrowExplicitClass, + double&>(true)) ); + VERIFY( (test_property<is_nothrow_constructible, NothrowExplicitClass, + int&>(true)) ); + VERIFY( (test_property<is_nothrow_constructible, NothrowExplicitClass, + double&, int&, double&>(true)) ); + + // Negative tests. + VERIFY( (test_property<is_nothrow_constructible, NoexceptExplicitClass, + void*>(false)) ); + VERIFY( (test_property<is_nothrow_constructible, NoexceptExplicitClass> + (false)) ); + VERIFY( (test_property<is_nothrow_constructible, NoexceptExplicitClass, + int, double>(false)) ); + VERIFY( (test_property<is_nothrow_constructible, NothrowExplicitClass, + void*>(false)) ); + VERIFY( (test_property<is_nothrow_constructible, NothrowExplicitClass> + (false)) ); + VERIFY( (test_property<is_nothrow_constructible, NothrowExplicitClass, + int, double>(false)) ); + + VERIFY( (test_property<is_nothrow_constructible, ExceptExplicitClass, + double&>(false)) ); + VERIFY( (test_property<is_nothrow_constructible, ExceptExplicitClass, + int&>(false)) ); + VERIFY( (test_property<is_nothrow_constructible, ExceptExplicitClass, + double&, int&, double&>(false)) ); + VERIFY( (test_property<is_nothrow_constructible, ThrowExplicitClass, + double&>(false)) ); + VERIFY( (test_property<is_nothrow_constructible, ThrowExplicitClass, + int&>(false)) ); + VERIFY( (test_property<is_nothrow_constructible, ThrowExplicitClass, + double&, int&, double&>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_pod/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_pod/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..241cff719 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_pod/requirements/explicit_instantiation.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2010-02-21 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_pod<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_pod/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_pod/requirements/typedefs.cc new file mode 100644 index 000000000..9c02b99e9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_pod/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2010-02-21 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_pod<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/is_pod/value.cc b/libstdc++-v3/testsuite/20_util/is_pod/value.cc new file mode 100644 index 000000000..e4926d5a6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_pod/value.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++0x" } +// 2010-02-21 Paolo Carlini <pcarlini@suse.de> +// +// 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 <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_pod; + using namespace __gnu_test; + + VERIFY( (test_category<is_pod, int>(true)) ); + VERIFY( (test_category<is_pod, float>(true)) ); + VERIFY( (test_category<is_pod, EnumType>(true)) ); + VERIFY( (test_category<is_pod, int*>(true)) ); + VERIFY( (test_category<is_pod, int(*)(int)>(true)) ); + VERIFY( (test_category<is_pod, int (ClassType::*)>(true)) ); + VERIFY( (test_category<is_pod, int (ClassType::*) (int)>(true)) ); + VERIFY( (test_category<is_pod, int[2]>(true)) ); + VERIFY( (test_category<is_pod, float[][3]>(true)) ); + VERIFY( (test_category<is_pod, EnumType[2][3][4]>(true)) ); + VERIFY( (test_category<is_pod, int*[3]>(true)) ); + VERIFY( (test_category<is_pod, int(*[][2])(int)>(true)) ); + VERIFY( (test_category<is_pod, int (ClassType::*[2][3])>(true)) ); + VERIFY( (test_category<is_pod, int (ClassType::*[][2][3]) (int)>(true)) ); + VERIFY( (test_category<is_pod, ClassType>(true)) ); + VERIFY( (test_category<is_pod, PODType>(true)) ); + + VERIFY( (test_category<is_pod, void>(false)) ); + VERIFY( (test_category<is_pod, NType>(false)) ); + VERIFY( (test_category<is_pod, TType>(false)) ); + VERIFY( (test_category<is_pod, SLType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_reference/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_reference/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..faf66d772 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_reference/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_reference<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_reference/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_reference/requirements/typedefs.cc new file mode 100644 index 000000000..ff572915f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_reference/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_reference<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/is_reference/value.cc b/libstdc++-v3/testsuite/20_util/is_reference/value.cc new file mode 100644 index 000000000..a6782ab9a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_reference/value.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_reference; + using namespace __gnu_test; + + VERIFY( (test_category<is_reference, int&>(true)) ); + VERIFY( (test_category<is_reference, ClassType&>(true)) ); + VERIFY( (test_category<is_reference, int(&)(int)>(true)) ); + VERIFY( (test_category<is_reference, int&&>(true)) ); + VERIFY( (test_category<is_reference, ClassType&&>(true)) ); + VERIFY( (test_category<is_reference, int(&&)(int)>(true)) ); + + // Sanity check. + VERIFY( (test_category<is_reference, ClassType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_rvalue_reference/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_rvalue_reference/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..336881339 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_rvalue_reference/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_rvalue_reference<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_rvalue_reference/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_rvalue_reference/requirements/typedefs.cc new file mode 100644 index 000000000..b7523bb8d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_rvalue_reference/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_rvalue_reference<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/is_rvalue_reference/value.cc b/libstdc++-v3/testsuite/20_util/is_rvalue_reference/value.cc new file mode 100644 index 000000000..1e83d0514 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_rvalue_reference/value.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_rvalue_reference; + using namespace __gnu_test; + + VERIFY( (test_category<is_rvalue_reference, int&&>(true)) ); + VERIFY( (test_category<is_rvalue_reference, ClassType&&>(true)) ); + VERIFY( (test_category<is_rvalue_reference, int(&&)(int)>(true)) ); + + // Sanity check. + VERIFY( (test_category<is_rvalue_reference, int&>(false)) ); + VERIFY( (test_category<is_rvalue_reference, ClassType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_scalar/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_scalar/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..1ff9ddc74 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_scalar/requirements/explicit_instantiation.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_scalar<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_scalar/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_scalar/requirements/typedefs.cc new file mode 100644 index 000000000..b2d0dd17c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_scalar/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// 2010-11-30 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/>. + +// +// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +void test01() +{ + // Check for required typedefs + typedef std::is_scalar<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/is_scalar/value.cc b/libstdc++-v3/testsuite/20_util/is_scalar/value.cc new file mode 100644 index 000000000..7d6521ed6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_scalar/value.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// 2010-11-30 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 <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_scalar; + using namespace __gnu_test; + + VERIFY( (test_category<is_scalar, int>(true)) ); + VERIFY( (test_category<is_scalar, float>(true)) ); + VERIFY( (test_category<is_scalar, EnumType>(true)) ); + VERIFY( (test_category<is_scalar, int*>(true)) ); + VERIFY( (test_category<is_scalar, int(*)(int)>(true)) ); + VERIFY( (test_category<is_scalar, int (ClassType::*)>(true)) ); + VERIFY( (test_category<is_scalar, int (ClassType::*) (int)>(true)) ); + VERIFY( (test_category<is_scalar, std::nullptr_t>(true)) ); + + // Sanity check. + VERIFY( (test_category<is_scalar, ClassType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_signed/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_signed/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..d64ce7e40 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_signed/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_signed<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_signed/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_signed/requirements/typedefs.cc new file mode 100644 index 000000000..6706c60bf --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_signed/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-24 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_signed<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/is_signed/value.cc b/libstdc++-v3/testsuite/20_util/is_signed/value.cc new file mode 100644 index 000000000..194e268b6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_signed/value.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-24 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_signed; + using namespace __gnu_test; + + VERIFY( (test_category<is_signed, void>(false)) ); + + VERIFY( (test_category<is_signed, char>(char(-1) < char(0))) ); + VERIFY( (test_category<is_signed, signed char>(true)) ); + VERIFY( (test_category<is_signed, unsigned char>(false)) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( (test_category<is_signed, wchar_t>(wchar_t(-1) < wchar_t(0))) ); +#endif + VERIFY( (test_category<is_signed, short>(true)) ); + VERIFY( (test_category<is_signed, unsigned short>(false)) ); + VERIFY( (test_category<is_signed, int>(true)) ); + VERIFY( (test_category<is_signed, unsigned int>(false)) ); + VERIFY( (test_category<is_signed, long>(true)) ); + VERIFY( (test_category<is_signed, unsigned long>(false)) ); + VERIFY( (test_category<is_signed, long long>(true)) ); + VERIFY( (test_category<is_signed, unsigned long long>(false)) ); + + VERIFY( (test_category<is_signed, float>(true)) ); + VERIFY( (test_category<is_signed, double>(true)) ); + VERIFY( (test_category<is_signed, long double>(true)) ); + + // Sanity check. + VERIFY( (test_category<is_signed, ClassType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_standard_layout/requiremenents/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_standard_layout/requiremenents/explicit_instantiation.cc new file mode 100644 index 000000000..619dc3e6b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_standard_layout/requiremenents/explicit_instantiation.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2010-02-21 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_standard_layout<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_standard_layout/requiremenents/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_standard_layout/requiremenents/typedefs.cc new file mode 100644 index 000000000..e209101e4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_standard_layout/requiremenents/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2010-02-21 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_standard_layout<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/is_standard_layout/value.cc b/libstdc++-v3/testsuite/20_util/is_standard_layout/value.cc new file mode 100644 index 000000000..7ef860906 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_standard_layout/value.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-23 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 <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_standard_layout; + using namespace __gnu_test; + + VERIFY( (test_category<is_standard_layout, SLType>(true)) ); + VERIFY( (test_category<is_standard_layout, PODType>(true)) ); + + VERIFY( (test_category<is_standard_layout, NType>(false)) ); + VERIFY( (test_category<is_standard_layout, TType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_trivial/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_trivial/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..043d12230 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_trivial/requirements/explicit_instantiation.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2010-02-21 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/>. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_trivial<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_trivial/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_trivial/requirements/typedefs.cc new file mode 100644 index 000000000..4b8047f5c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_trivial/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2010-02-21 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_trivial<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/is_trivial/value.cc b/libstdc++-v3/testsuite/20_util/is_trivial/value.cc new file mode 100644 index 000000000..e6ff8fac5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_trivial/value.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-23 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 <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_trivial; + using namespace __gnu_test; + + VERIFY( (test_category<is_trivial, TType>(true)) ); + VERIFY( (test_category<is_trivial, PODType>(true)) ); + + VERIFY( (test_category<is_trivial, NType>(false)) ); + VERIFY( (test_category<is_trivial, SLType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..52b8406e2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct is_unsigned<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/typedefs.cc new file mode 100644 index 000000000..3538edca7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-24 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 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/>. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_unsigned<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/is_unsigned/value.cc b/libstdc++-v3/testsuite/20_util/is_unsigned/value.cc new file mode 100644 index 000000000..5163cf975 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_unsigned/value.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-24 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_unsigned; + using namespace __gnu_test; + + VERIFY( (test_category<is_unsigned, void>(false)) ); + + VERIFY( (test_category<is_unsigned, char>(char(-1) > char(0))) ); + VERIFY( (test_category<is_unsigned, signed char>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned char>(true)) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( (test_category<is_unsigned, wchar_t>(wchar_t(-1) > wchar_t(0))) ); +#endif + VERIFY( (test_category<is_unsigned, short>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned short>(true)) ); + VERIFY( (test_category<is_unsigned, int>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned int>(true)) ); + VERIFY( (test_category<is_unsigned, long>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned long>(true)) ); + VERIFY( (test_category<is_unsigned, long long>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned long long>(true)) ); + + VERIFY( (test_category<is_unsigned, float>(false)) ); + VERIFY( (test_category<is_unsigned, double>(false)) ); + VERIFY( (test_category<is_unsigned, long double>(false)) ); + + // Sanity check. + VERIFY( (test_category<is_unsigned, ClassType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..77061d5b4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct make_signed<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-1.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-1.cc new file mode 100644 index 000000000..6c21a1e75 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-1.cc @@ -0,0 +1,65 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-05-03 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 2008, 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> + +enum test_enum { first_selection }; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::make_signed; + using std::is_same; + using std::is_signed; + + // Positive tests. + typedef make_signed<const int>::type test2_type; + VERIFY( (is_same<test2_type, const int>::value) ); + + typedef make_signed<const unsigned int>::type test21c_type; + VERIFY( (is_same<test21c_type, const signed int>::value) ); + + typedef make_signed<volatile unsigned int>::type test21v_type; + VERIFY( (is_same<test21v_type, volatile signed int>::value) ); + + typedef make_signed<const volatile unsigned int>::type test21cv_type; + VERIFY( (is_same<test21cv_type, const volatile signed int>::value) ); + + typedef make_signed<const char>::type test22_type; + VERIFY( (is_same<test22_type, const signed char>::value) ); + +#ifdef _GLIBCXX_USE_WCHAR_T + typedef make_signed<volatile wchar_t>::type test23_type; + VERIFY( (is_same<test23_type, volatile signed wchar_t>::value) ); +#endif + + // Chapter 48, chapter 20. Smallest rank such that new signed type same size. + typedef make_signed<test_enum>::type test25_type; + VERIFY( is_signed<test25_type>::value ); + VERIFY( sizeof(test25_type) == sizeof(test_enum) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-2.cc new file mode 100644 index 000000000..cb40b7bff --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-2.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++0x -funsigned-char -fshort-enums" } +// { dg-options "-std=gnu++0x -funsigned-char -fshort-enums -Wl,--no-enum-size-warning" { target arm*-*-linux*eabi } } + +// 2007-05-03 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 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> + +// Ensure that this enum has "short" as its underlying type. +enum test_enum { first_selection = ((unsigned char)-1) + 1 }; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::make_signed; + using std::is_same; + + // Positive tests. + typedef make_signed<const int>::type test2_type; + VERIFY( (is_same<test2_type, const int>::value) ); + + typedef make_signed<const unsigned int>::type test21c_type; + VERIFY( (is_same<test21c_type, const signed int>::value) ); + + typedef make_signed<volatile unsigned int>::type test21v_type; + VERIFY( (is_same<test21v_type, volatile signed int>::value) ); + + typedef make_signed<const volatile unsigned int>::type test21cv_type; + VERIFY( (is_same<test21cv_type, const volatile signed int>::value) ); + + typedef make_signed<const char>::type test22_type; + VERIFY( (is_same<test22_type, const signed char>::value) ); + +#ifdef _GLIBCXX_USE_WCHAR_T + typedef make_signed<volatile wchar_t>::type test23_type; + VERIFY( (is_same<test23_type, volatile signed wchar_t>::value) ); +#endif + + typedef make_signed<test_enum>::type test25_type; + VERIFY( (is_same<test25_type, short>::value) ); +} + +int main() +{ + test01(); + return 0; +} 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 new file mode 100644 index 000000000..5179abfeb --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc @@ -0,0 +1,52 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-05-03 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 2008, 2009, 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 <type_traits> +#include <testsuite_character.h> + +enum test_enum { first_selection }; + +void test01() +{ + using std::make_signed; + + // Negative tests. + typedef make_signed<bool>::type test1_type; + + typedef make_signed<__gnu_test::pod_uint>::type test2_type; + + typedef make_signed<int[4]>::type test3_type; + + typedef void (fn_type) (); + typedef make_signed<fn_type>::type test4_type; + + typedef make_signed<float>::type test5_type; +} + +// { dg-error "does not name a type" "" { target *-*-* } 33 } +// { dg-error "instantiated from here" "" { target *-*-* } 35 } +// { dg-error "instantiated from here" "" { target *-*-* } 37 } +// { dg-error "instantiated from here" "" { target *-*-* } 40 } +// { dg-error "instantiated from here" "" { target *-*-* } 42 } + +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1097 } +// { dg-error "declaration of" "" { target *-*-* } 1061 } diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..7821dd7ae --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct make_unsigned<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-1.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-1.cc new file mode 100644 index 000000000..9d96d5b89 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-1.cc @@ -0,0 +1,66 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-05-03 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 2008, 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> + +enum test_enum { first_selection }; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::make_unsigned; + using std::is_same; + using std::is_unsigned; + + // Positive tests. + typedef make_unsigned<const unsigned int>::type test2_type; + VERIFY( (is_same<test2_type, const unsigned int>::value) ); + + typedef make_unsigned<const signed int>::type test21c_type; + VERIFY( (is_same<test21c_type, const unsigned int>::value) ); + + typedef make_unsigned<volatile signed int>::type test21v_type; + VERIFY( (is_same<test21v_type, volatile unsigned int>::value) ); + + typedef make_unsigned<const volatile signed int>::type test21cv_type; + VERIFY( (is_same<test21cv_type, const volatile unsigned int>::value) ); + + typedef make_unsigned<const char>::type test22_type; + VERIFY( (is_same<test22_type, const unsigned char>::value) ); + +#ifdef _GLIBCXX_USE_WCHAR_T + typedef make_unsigned<volatile wchar_t>::type test23_type; + VERIFY( (is_same<test23_type, volatile wchar_t>::value) ); +#endif + + // Chapter 48, chapter 20. Smallest rank such that new unsigned type + // same size. + typedef make_unsigned<test_enum>::type test25_type; + VERIFY( is_unsigned<test25_type>::value ); + VERIFY( sizeof(test25_type) == sizeof(test_enum) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-2.cc new file mode 100644 index 000000000..d71c01282 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-2.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++0x -funsigned-char -fshort-enums" } +// { dg-options "-std=gnu++0x -funsigned-char -fshort-enums -Wl,--no-enum-size-warning" { target arm*-*-linux*eabi } } + +// 2007-05-03 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 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> + +// Ensure that this enum has "short" as its underlying type. +enum test_enum { first_selection = ((unsigned char)-1) + 1 }; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::make_unsigned; + using std::is_same; + + // Positive tests. + typedef make_unsigned<const unsigned int>::type test2_type; + VERIFY( (is_same<test2_type, const unsigned int>::value) ); + + typedef make_unsigned<const signed int>::type test21c_type; + VERIFY( (is_same<test21c_type, const unsigned int>::value) ); + + typedef make_unsigned<volatile signed int>::type test21v_type; + VERIFY( (is_same<test21v_type, volatile unsigned int>::value) ); + + typedef make_unsigned<const volatile signed int>::type test21cv_type; + VERIFY( (is_same<test21cv_type, const volatile unsigned int>::value) ); + + typedef make_unsigned<const char>::type test22_type; + VERIFY( (is_same<test22_type, const unsigned char>::value) ); + +#ifdef _GLIBCXX_USE_WCHAR_T + typedef make_unsigned<volatile wchar_t>::type test23_type; + VERIFY( (is_same<test23_type, volatile wchar_t>::value) ); +#endif + + typedef make_unsigned<test_enum>::type test25_type; + VERIFY( (is_same<test25_type, unsigned short>::value) ); +} + +int main() +{ + test01(); + return 0; +} 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 new file mode 100644 index 000000000..1a1724d74 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc @@ -0,0 +1,52 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-05-03 Benjamin Kosnik <bkoz@redhat.com> +// +// Copyright (C) 2007, 2008, 2009, 2010, 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/>. + +#include <type_traits> +#include <testsuite_character.h> + +enum test_enum { first_selection }; + +void test01() +{ + using std::make_unsigned; + + // Negative tests. + typedef make_unsigned<bool>::type test1_type; + + typedef make_unsigned<__gnu_test::pod_uint>::type test2_type; + + typedef make_unsigned<int[4]>::type test3_type; + + typedef void (fn_type) (); + typedef make_unsigned<fn_type>::type test4_type; + + typedef make_unsigned<float>::type test5_type; +} + +// { dg-error "does not name a type" "" { target *-*-* } 33 } +// { dg-error "instantiated from here" "" { target *-*-* } 35 } +// { dg-error "instantiated from here" "" { target *-*-* } 37 } +// { dg-error "instantiated from here" "" { target *-*-* } 40 } +// { dg-error "instantiated from here" "" { target *-*-* } 42 } + +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1020 } +// { dg-error "declaration of" "" { target *-*-* } 984 } diff --git a/libstdc++-v3/testsuite/20_util/monotonic_clock/constexpr_data.cc b/libstdc++-v3/testsuite/20_util/monotonic_clock/constexpr_data.cc new file mode 100644 index 000000000..34477ea18 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/monotonic_clock/constexpr_data.cc @@ -0,0 +1,52 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +namespace __gnu_test +{ + struct constexpr_member_data + { + template<typename _Ttesttype> + void + operator()() + { + struct _Concept + { + void __constraint() + { + constexpr auto v1 __attribute__((unused)) + = _Ttesttype::is_monotonic; + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + __gnu_test::constexpr_member_data test; + test.operator()<std::chrono::monotonic_clock>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/move/1.cc b/libstdc++-v3/testsuite/20_util/move/1.cc new file mode 100644 index 000000000..bb7b4e601 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/move/1.cc @@ -0,0 +1,45 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-07-10 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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 <memory> +#include <utility> + +template<class T, class A1> + std::shared_ptr<T> + factory(A1&& a1) + { + return std::shared_ptr<T>(new T(std::forward<A1>(a1))); + } + +struct A +{ + A(); + A(const A&); + A(A&&); +}; + +void g() +{ + A a; + std::shared_ptr<A> sp1 = factory<A>(a); + std::shared_ptr<A> sp2 = factory<A>(std::move(a)); +} diff --git a/libstdc++-v3/testsuite/20_util/move/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/move/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..53b4e9bb8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/move/requirements/explicit_instantiation.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2007-07-10 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing utility with NO OTHER INCLUDES. + +#include <utility> + +namespace std +{ + typedef short test_type; + template std::remove_reference<test_type>::type&& move(test_type&&); +} diff --git a/libstdc++-v3/testsuite/20_util/owner_less/cmp.cc b/libstdc++-v3/testsuite/20_util/owner_less/cmp.cc new file mode 100644 index 000000000..e1524cc18 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/owner_less/cmp.cc @@ -0,0 +1,135 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.13.4 Template class owner_less [util.smartptr.ownerless] + +#include <memory> +#include <algorithm> +#include <testsuite_hooks.h> + +struct A { }; + +struct B { A a[2]; }; + +// 20.8.13.4 Template class owner_less [util.smartptr.ownerless] + +int +test01() +{ + bool test __attribute__((unused)) = true; + + // test empty shared_ptrs compare equivalent + std::owner_less<std::shared_ptr<A>> less; + std::owner_less<std::weak_ptr<A>> wless; + std::shared_ptr<A> p1; + std::shared_ptr<A> p2; + VERIFY( !less(p1, p2) && !less(p2, p1) ); + std::weak_ptr<A> p3; + VERIFY( !less(p1, p3) && !less(p3, p1) ); + VERIFY( !wless(p1, p3) && !wless(p3, p1) ); + return 0; +} + + +// Construction from pointer +int +test02() +{ + bool test __attribute__((unused)) = true; + + std::owner_less<std::shared_ptr<A>> less; + std::owner_less<std::weak_ptr<A>> wless; + + std::shared_ptr<A> empty; + + std::shared_ptr<A> a1(new A); + VERIFY( less(empty, a1) || less(a1, empty) ); + + std::shared_ptr<A> a2(new A); + VERIFY( less(a1, a2) || less(a2, a1) ); + + std::weak_ptr<A> w1(a1); + VERIFY( !less(a1, w1) && !less(w1, a1) ); + + std::weak_ptr<A> w2(a2); + VERIFY( wless(w1, w2) || wless(w2, w1) ); + + a1.reset(); + VERIFY( !less(empty, a1) && !less(a1, empty) ); + VERIFY( less(a1, w1) || less(w1, a1) ); + + a2.reset(); + VERIFY( !less(a2, a1) && !less(a1, a2) ); + + return 0; +} + +// aliasing +int +test03() +{ + bool test __attribute__((unused)) = true; + + std::owner_less<std::shared_ptr<A>> less; + std::owner_less<std::weak_ptr<A>> wless; + + std::shared_ptr<B> b(new B); + std::shared_ptr<A> a0(b, &b->a[0]); + std::shared_ptr<A> a1(b, &b->a[1]); + // values are different but owners are equivalent: + VERIFY( a0 < a1 && !less(a0, a1) && !less(a1, a0) ); + + std::weak_ptr<A> w0(a0); + std::weak_ptr<A> w1(a1); + VERIFY( !wless(w0, w1) && !wless(w1, w0) ); + VERIFY( !less(a0, w1) && !less(w1, a0) ); + VERIFY( !wless(w0, a1) && !wless(a1, w0) ); + + return 0; +} + +// strict weak ordering +int +test04() +{ + bool test __attribute__((unused)) = true; + + std::owner_less<std::shared_ptr<A>> less; + + std::shared_ptr<A> a[3]; + a[0].reset(new A); + a[1].reset(new A); + a[2].reset(new A); + std::sort(a, a+3, less); + VERIFY( !less(a[0], a[0]) ); + VERIFY( less(a[0], a[1]) && !less(a[1], a[0]) ); + VERIFY( less(a[0], a[1]) && less(a[1], a[2]) && less(a[0], a[2]) ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/1.cc b/libstdc++-v3/testsuite/20_util/pair/1.cc new file mode 100644 index 000000000..f5b15f755 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/1.cc @@ -0,0 +1,78 @@ +// 2001-06-18 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2004, 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/>. + +// 20.2.2 Pairs + +#include <utility> +#include <testsuite_hooks.h> + +class gnu_obj +{ + int i; +public: + gnu_obj(int arg = 0): i(arg) { } + bool operator==(const gnu_obj& rhs) const { return i == rhs.i; } + bool operator<(const gnu_obj& rhs) const { return i < rhs.i; } +}; + +template<typename T> + struct gnu_t + { + bool b; + public: + gnu_t(bool arg = 0): b(arg) { } + bool operator==(const gnu_t& rhs) const { return b == rhs.b; } + bool operator<(const gnu_t& rhs) const { return int(b) < int(rhs.b); } + }; + + +// heterogeneous +void test01() +{ + bool test __attribute__((unused)) = true; + + std::pair<bool, long> p_bl_1(true, 433); + std::pair<bool, long> p_bl_2 = std::make_pair(true, 433); + VERIFY( p_bl_1 == p_bl_2 ); + VERIFY( !(p_bl_1 < p_bl_2) ); + + std::pair<const char*, float> p_sf_1("total enlightenment", 433.00); + std::pair<const char*, float> p_sf_2 = std::make_pair("total enlightenment", + 433.00); + VERIFY( p_sf_1 == p_sf_2 ); + VERIFY( !(p_sf_1 < p_sf_2) ); + + std::pair<const char*, gnu_obj> p_sg_1("enlightenment", gnu_obj(5)); + std::pair<const char*, gnu_obj> p_sg_2 = std::make_pair("enlightenment", + gnu_obj(5)); + VERIFY( p_sg_1 == p_sg_2 ); + VERIFY( !(p_sg_1 < p_sg_2) ); + + std::pair<gnu_t<long>, gnu_obj> p_st_1(gnu_t<long>(false), gnu_obj(5)); + std::pair<gnu_t<long>, gnu_obj> p_st_2 = std::make_pair(gnu_t<long>(false), + gnu_obj(5)); + VERIFY( p_st_1 == p_st_2 ); + VERIFY( !(p_st_1 < p_st_2) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/2.cc b/libstdc++-v3/testsuite/20_util/pair/2.cc new file mode 100644 index 000000000..0826cdb2f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/2.cc @@ -0,0 +1,59 @@ +// 2001-06-18 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2004, 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/>. + +// 20.2.2 Pairs + +#include <utility> +#include <testsuite_hooks.h> + +class gnu_obj +{ + int i; +public: + gnu_obj(int arg = 0): i(arg) { } + bool operator==(const gnu_obj& rhs) const { return i == rhs.i; } + bool operator<(const gnu_obj& rhs) const { return i < rhs.i; } +}; + +template<typename T> + struct gnu_t + { + bool b; + public: + gnu_t(bool arg = 0): b(arg) { } + bool operator==(const gnu_t& rhs) const { return b == rhs.b; } + bool operator<(const gnu_t& rhs) const { return int(b) < int(rhs.b); } + }; + +// homogeneous +void test02() +{ + bool test __attribute__((unused)) = true; + + std::pair<bool, bool> p_bb_1(true, false); + std::pair<bool, bool> p_bb_2 = std::make_pair(true, false); + VERIFY( p_bb_1 == p_bb_2 ); + VERIFY( !(p_bb_1 < p_bb_2) ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/3.cc b/libstdc++-v3/testsuite/20_util/pair/3.cc new file mode 100644 index 000000000..fc19a4acd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/3.cc @@ -0,0 +1,78 @@ +// 2001-06-18 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2004, 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/>. + +// 20.2.2 Pairs + +#include <utility> +#include <testsuite_hooks.h> + +class gnu_obj +{ + int i; +public: + gnu_obj(int arg = 0): i(arg) { } + bool operator==(const gnu_obj& rhs) const { return i == rhs.i; } + bool operator<(const gnu_obj& rhs) const { return i < rhs.i; } +}; + +template<typename T> + struct gnu_t + { + bool b; + public: + gnu_t(bool arg = 0): b(arg) { } + bool operator==(const gnu_t& rhs) const { return b == rhs.b; } + bool operator<(const gnu_t& rhs) const { return int(b) < int(rhs.b); } + }; + + +// const +void test03() +{ + bool test __attribute__((unused)) = true; + + const std::pair<bool, long> p_bl_1(true, 433); + const std::pair<bool, long> p_bl_2 = std::make_pair(true, 433); + VERIFY( p_bl_1 == p_bl_2 ); + VERIFY( !(p_bl_1 < p_bl_2) ); + + const std::pair<const char*, float> p_sf_1("total enlightenment", 433.00); + const std::pair<const char*, float> p_sf_2 = + std::make_pair("total enlightenment", 433.00); + VERIFY( p_sf_1 == p_sf_2 ); + VERIFY( !(p_sf_1 < p_sf_2) ); + + const std::pair<const char*, gnu_obj> p_sg_1("enlightenment", gnu_obj(5)); + const std::pair<const char*, gnu_obj> p_sg_2 = + std::make_pair("enlightenment", gnu_obj(5)); + VERIFY( p_sg_1 == p_sg_2 ); + VERIFY( !(p_sg_1 < p_sg_2) ); + + const std::pair<gnu_t<long>, gnu_obj> p_st_1(gnu_t<long>(false), gnu_obj(5)); + const std::pair<gnu_t<long>, gnu_obj> p_st_2 = + std::make_pair(gnu_t<long>(false), gnu_obj(5)); + VERIFY( p_st_1 == p_st_2 ); + VERIFY( !(p_st_1 < p_st_2) ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/4.cc b/libstdc++-v3/testsuite/20_util/pair/4.cc new file mode 100644 index 000000000..7431fc1e7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/4.cc @@ -0,0 +1,66 @@ +// 2001-06-18 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2004, 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/>. + +// 20.2.2 Pairs + +#include <utility> +#include <testsuite_hooks.h> + +class gnu_obj +{ + int i; +public: + gnu_obj(int arg = 0): i(arg) { } + bool operator==(const gnu_obj& rhs) const { return i == rhs.i; } + bool operator<(const gnu_obj& rhs) const { return i < rhs.i; } +}; + +template<typename T> + struct gnu_t + { + bool b; + public: + gnu_t(bool arg = 0): b(arg) { } + bool operator==(const gnu_t& rhs) const { return b == rhs.b; } + bool operator<(const gnu_t& rhs) const { return int(b) < int(rhs.b); } + }; + +// const& +void test04() +{ + bool test __attribute__((unused)) = true; + const gnu_obj& obj1 = gnu_obj(5); + const std::pair<const char*, gnu_obj> p_sg_1("enlightenment", obj1); + const std::pair<const char*, gnu_obj> p_sg_2 = + std::make_pair("enlightenment", obj1); + VERIFY( p_sg_1 == p_sg_2 ); + VERIFY( !(p_sg_1 < p_sg_2) ); + + const gnu_t<long>& tmpl1 = gnu_t<long>(false); + const std::pair<gnu_t<long>, gnu_obj> p_st_1(tmpl1, obj1); + const std::pair<gnu_t<long>, gnu_obj> p_st_2 = std::make_pair(tmpl1, obj1); + VERIFY( p_st_1 == p_st_2 ); + VERIFY( !(p_st_1 < p_st_2) ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/40925.cc b/libstdc++-v3/testsuite/20_util/pair/40925.cc new file mode 100644 index 000000000..6abeb617f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/40925.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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> + +struct X +{ + explicit X(int, int) { } + +private: + X(const X&) = delete; +}; + +struct move_only +{ + move_only() { } + move_only(move_only&&) { } + +private: + move_only(const move_only&) = delete; +}; + +// libstdc++/40925 +void test01() +{ + int *ip = 0; + int X::*mp = 0; + + std::pair<int*, int*> p1(0, 0); + std::pair<int*, int*> p2(ip, 0); + std::pair<int*, int*> p3(0, ip); + std::pair<int*, int*> p4(ip, ip); + + std::pair<int X::*, int*> p5(0, 0); + std::pair<int X::*, int X::*> p6(mp, 0); + std::pair<int X::*, int X::*> p7(0, mp); + std::pair<int X::*, int X::*> p8(mp, mp); + + std::pair<int*, move_only> p9(0, move_only()); + std::pair<int X::*, move_only> p10(0, move_only()); + std::pair<move_only, int*> p11(move_only(), 0); + std::pair<move_only, int X::*> p12(move_only(), 0); + + std::pair<int*, move_only> p13(ip, move_only()); + std::pair<int X::*, move_only> p14(mp, move_only()); + std::pair<move_only, int*> p15(move_only(), ip); + std::pair<move_only, int X::*> p16(move_only(), mp); + + std::pair<move_only, move_only> p17(move_only(), move_only()); +} diff --git a/libstdc++-v3/testsuite/20_util/pair/44487.cc b/libstdc++-v3/testsuite/20_util/pair/44487.cc new file mode 100644 index 000000000..833d98645 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/44487.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <utility> + +int x, y; + +std::pair<int&, int&> +foo1() +{ + std::pair<int&, int&> blah(x, y); + return blah; +} + +std::pair<int&, int&> +foo2() +{ + const std::pair<int&, int&> blah(x, y); + return blah; +} + +std::pair<int&, int&> +foo3() +{ + std::pair<int&, int&> blah(x, y); + return std::pair<int&, int&>(std::move(blah)); +} + +std::pair<int&, int&> +foo4() +{ + const std::pair<int&, int&> blah(x, y); + return std::pair<int&, int&>(std::move(blah)); +} diff --git a/libstdc++-v3/testsuite/20_util/pair/comparison_operators/constexpr.cc b/libstdc++-v3/testsuite/20_util/pair/comparison_operators/constexpr.cc new file mode 100644 index 000000000..d5dc6e4e1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/comparison_operators/constexpr.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <utility> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_comparison_operators test; + test.operator()<std::pair<int, int>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc new file mode 100644 index 000000000..1c854627e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc @@ -0,0 +1,39 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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_common_types.h> + +int main() +{ + __gnu_test::constexpr_default_constructible test1; + test1.operator()<std::pair<int, int>>(); + + __gnu_test::constexpr_single_value_constructible test2; + test2.operator()<std::pair<int, int>, std::pair<int, int>>(); + test2.operator()<std::pair<int, int>, std::pair<short, short>>(); + + // test 3 + const int i1(129); + const int i2(6); + constexpr std::pair<int, int> p3(i1, i2); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/moveable.cc b/libstdc++-v3/testsuite/20_util/pair/moveable.cc new file mode 100644 index 000000000..9abdd8107 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/moveable.cc @@ -0,0 +1,63 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on pair, and also vector. If the implementation +// changes this test may begin to fail. + +#include <vector> +#include <utility> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +void +test1() +{ + std::pair<int,int> a(1,1),b(2,2); + a=std::move(b); + VERIFY(a.first == 2 && a.second == 2 && b.first == 2 && b.second == 2); + std::pair<int,int> c(std::move(a)); + VERIFY(c.first == 2 && c.second == 2 && a.first == 2 && a.second == 2); +} + +void +test2() +{ + std::vector<int> v,w; + v.push_back(1); + w.push_back(2); + w.push_back(2); + std::pair<int, std::vector<int> > p = make_pair(1,v); + std::pair<int, std::vector<int> > q = make_pair(2,w); + p = std::move(q); + VERIFY(p.first == 2 && q.first == 2 && + p.second.size() == 2 && q.second.size() == 0); + std::pair<int, std::vector<int> > r(std::move(p)); + VERIFY(r.first == 2 && p.first == 2 && + r.second.size() == 2 && p.second.size() == 0); +} + +int +main() +{ + test1(); + test2(); +} diff --git a/libstdc++-v3/testsuite/20_util/pair/piecewise.cc b/libstdc++-v3/testsuite/20_util/pair/piecewise.cc new file mode 100644 index 000000000..ef7147320 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/piecewise.cc @@ -0,0 +1,98 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-04-30 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/>. + +// Tuple + +#include <utility> +#include <tuple> +#include <testsuite_hooks.h> + +struct type_zero +{ + type_zero() : n_(757) { } + + type_zero(const type_zero&) = delete; + type_zero(type_zero&& other) : n_(other.n_) { } + + int get() const { return n_; } + +private: + int n_; +}; + +struct type_one +{ + type_one(int n) : n_(n) { } + + type_one(const type_one&) = delete; + type_one(type_one&& other) : n_(other.n_) { } + + int get() const { return n_; } + +private: + int n_; +}; + +struct type_two +{ + type_two(int n1, int n2) : n1_(n1), n2_(n2) { } + + type_two(const type_two&) = delete; + type_two(type_two&& other) : n1_(other.n1_), n2_(other.n2_) { } + + int get1() const { return n1_; } + int get2() const { return n2_; } + +private: + int n1_, n2_; +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::pair<type_one, type_zero> pp0(std::piecewise_construct_t(), + std::forward_as_tuple(-3), + std::forward_as_tuple()); + VERIFY( pp0.first.get() == -3 ); + VERIFY( pp0.second.get() == 757 ); + + std::pair<type_one, type_two> pp1(std::piecewise_construct_t(), + std::forward_as_tuple(6), + std::forward_as_tuple(5, 4)); + VERIFY( pp1.first.get() == 6 ); + VERIFY( pp1.second.get1() == 5 ); + VERIFY( pp1.second.get2() == 4 ); + + std::pair<type_two, type_two> pp2(std::piecewise_construct_t(), + std::forward_as_tuple(2, 1), + std::forward_as_tuple(-1, -3)); + VERIFY( pp2.first.get1() == 2 ); + VERIFY( pp2.first.get2() == 1 ); + VERIFY( pp2.second.get1() == -1 ); + VERIFY( pp2.second.get2() == -3 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/requirements/dr801.cc b/libstdc++-v3/testsuite/20_util/pair/requirements/dr801.cc new file mode 100644 index 000000000..36d380dcf --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/requirements/dr801.cc @@ -0,0 +1,52 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <type_traits> + +// DR 801, pair and tuple vs. "passed in registers" +void test_trivial() +{ + // PODType, TType, NType, SLType, LType, NLType, LTypeDerived + typedef std::pair<int, int> pair_type; + // static_assert(std::is_literal_type<pair_type>::value, "! literal"); + static_assert(std::has_trivial_copy_constructor<pair_type>::value, + "! triv copy"); + static_assert(std::has_trivial_destructor<pair_type>::value, + "! triv destructor"); + // static_assert(std::is_standard_layout<pair_type>::value, + // "! standard layout"); + + // Negative + /* + static_assert(std::has_trivial_default_constructor<pair_type>::value, + "! triv default"); + static_assert(std::has_trivial_copy_assign<pair_type>::value, + "! triv assign"); + static_assert(std::is_trivial<pair_type>::value, "! triv"); + static_assert(std::is_pod<pair_type>::value, "! pod"); + */ +} + +int main() +{ + test_trivial(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/20_util/pair/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..262c575cf --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <utility> + +template class std::pair<int, long>; diff --git a/libstdc++-v3/testsuite/20_util/pair/swap.cc b/libstdc++-v3/testsuite/20_util/pair/swap.cc new file mode 100644 index 000000000..a76f5f3cb --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/swap.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + typedef __gnu_test::uneq_allocator<double> ua_type; + ua_type one(1), two(2); + + std::pair<ua_type, int> p1(one, 1), p2(two, 2); + + p1.swap(p2); + VERIFY( p1.first.get_personality() == 2 ); + VERIFY( p1.second == 2 ); + VERIFY( p2.first.get_personality() == 1 ); + VERIFY( p2.second == 1 ); + + swap(p1, p2); + VERIFY( p2.first.get_personality() == 2 ); + VERIFY( p2.second == 2 ); + VERIFY( p1.first.get_personality() == 1 ); + VERIFY( p1.second == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp1.cc b/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp1.cc new file mode 100644 index 000000000..eb1bd212f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp1.cc @@ -0,0 +1,86 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009, 2010 Free Software Foundation +// +// 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 <ratio> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + VERIFY(( std::ratio_equal<std::ratio<2,6>, std::ratio<1,3>>::value == 1 )); + VERIFY(( std::ratio_equal<std::ratio<2,6>, std::ratio<1,4>>::value == 0 )); + + VERIFY( (std::ratio_not_equal<std::ratio<2,6>, + std::ratio<1,3>>::value == 0) ); + VERIFY( (std::ratio_not_equal<std::ratio<2,6>, + std::ratio<1,4>>::value == 1) ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + VERIFY( (std::ratio_less<std::ratio<1,4>, std::ratio<1,3>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<-1,3>, std::ratio<1,3>>::value == 1) ); + + VERIFY( (std::ratio_less<std::ratio<1,3>, std::ratio<1,4>>::value == 0) ); + VERIFY( (std::ratio_less<std::ratio<1,3>, std::ratio<-1,3>>::value == 0) ); + + VERIFY( (std::ratio_less<std::ratio<-1,3>, std::ratio<-1,4>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<0,4>, std::ratio<0,3>>::value == 0) ); + VERIFY( (std::ratio_less<std::ratio<1,3>, std::ratio<0,3>>::value == 0) ); + VERIFY( (std::ratio_less<std::ratio<0,3>, std::ratio<-1,4>>::value == 0) ); + + VERIFY( (std::ratio_less_equal<std::ratio<-1,3>, + std::ratio<-1,3>>::value == 1) ); + VERIFY( ( std::ratio_less_equal<std::ratio<1,4>, + std::ratio<1,3>>::value == 1) ); + + VERIFY( (std::ratio_less_equal<std::ratio<1,4>, + std::ratio<-1,3>>::value == 0) ); + VERIFY( (std::ratio_less_equal<std::ratio<1,3>, + std::ratio<-1,3>>::value == 0) ); + + VERIFY( (std::ratio_greater<std::ratio<1,3>, std::ratio<1,4>>::value == 1) ); + VERIFY( (std::ratio_greater<std::ratio<1,3>, std::ratio<-1,3>>::value == 1) ); + + VERIFY( (std::ratio_greater<std::ratio<1,4>, std::ratio<1,3>>::value == 0) ); + VERIFY( (std::ratio_greater<std::ratio<-1,3>, std::ratio<1,3>>::value == 0) ); + + VERIFY( (std::ratio_greater_equal<std::ratio<1,3>, + std::ratio<1,3>>::value == 1) ); + VERIFY( (std::ratio_greater_equal<std::ratio<1,3>, + std::ratio<-1,3>>::value == 1) ); + + VERIFY( (std::ratio_greater_equal<std::ratio<-1,3>, + std::ratio<1,3>>::value == 0) ); + VERIFY( (std::ratio_greater_equal<std::ratio<1,4>, + std::ratio<1,3>>::value == 0) ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp2.cc b/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp2.cc new file mode 100644 index 000000000..20da30cbe --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp2.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation +// +// 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 <ratio> +#include <testsuite_hooks.h> + +static const std::intmax_t M = INTMAX_MAX; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + // No overflow with same denominator + VERIFY( (std::ratio_less<std::ratio<M - 2, M>, + std::ratio<M - 1, M>>::value == 1) ); + + VERIFY( (std::ratio_less<std::ratio<M - 1, M>, + std::ratio<M - 2, M>>::value == 0) ); + + // No overflow if signs differ + VERIFY( (std::ratio_less<std::ratio<-M, M - 1>, + std::ratio<M - 1, M - 2>>::value == 1) ); + + VERIFY( (std::ratio_less<std::ratio<M - 1, M - 2>, + std::ratio<-M, M - 1>>::value == 0) ); + + // No overflow + VERIFY( (std::ratio_less<std::ratio<M, M - 1>, + std::ratio<M, M - 2>>::value == 1) ); + + VERIFY( (std::ratio_less<std::ratio<-M, M - 1>, + std::ratio<-M, M - 2>>::value == 0) ); + + VERIFY( (std::ratio_less<std::ratio<M - 2, M - 1>, + std::ratio<M - 1, M>>::value == 1) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp3.cc b/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp3.cc new file mode 100644 index 000000000..f8c0c486b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp3.cc @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2011-02-28 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2011 Free Software Foundation +// +// 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 <ratio> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + VERIFY( (std::ratio_less<std::ratio<59, 29131>, + std::ratio<59, 29129>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<4733, 13>, + std::ratio<4751, 13>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<25703, 25717>, + std::ratio<25733, 25741>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<631, 769>, + std::ratio<673, 773>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<8353, 16903>, + std::ratio<17891, 32099>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<2311, 18701>, + std::ratio<18457, 19571>>::value == 1) ); + + VERIFY( (std::ratio_less<std::ratio<60, 29132>, + std::ratio<60, 29130>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<4734, 14>, + std::ratio<4752, 14>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<25704, 25718>, + std::ratio<25732, 25742>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<632, 770>, + std::ratio<674, 774>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<8352, 16904>, + std::ratio<17892, 32100>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<2312, 18702>, + std::ratio<18458, 19572>>::value == 1) ); + + VERIFY( (std::ratio_less<std::ratio<58, 29130>, + std::ratio<58, 29128>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<4732, 12>, + std::ratio<4750, 12>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<25702, 25716>, + std::ratio<25734, 25740>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<630, 768>, + std::ratio<672, 772>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<8354, 16902>, + std::ratio<17890, 32102>>::value == 1) ); + VERIFY( (std::ratio_less<std::ratio<2310, 18700>, + std::ratio<18456, 19570>>::value == 1) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/cons/cons1.cc b/libstdc++-v3/testsuite/20_util/ratio/cons/cons1.cc new file mode 100644 index 000000000..a3dab54fd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/cons/cons1.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2008-07-03 Chris Fairles <chris.fairles@gmail.com> + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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 <ratio> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ratio<1,3> r0; + std::ratio<2,6> r1; + std::ratio<2,-6> r2; + std::ratio<-2,6> r3; + + VERIFY( r0.num == 1 ); + VERIFY( r0.den == 3 ); + + VERIFY( r1.num == r0.num ); + VERIFY( r1.den == r0.den ); + VERIFY( r2.num == -r0.num ); + VERIFY( r2.den == r0.den ); + VERIFY( r3.num == -r0.num ); + VERIFY( r3.den == r0.den ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc new file mode 100644 index 000000000..ca91e46c8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc @@ -0,0 +1,54 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation +// +// 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 <ratio> + +void +test01() +{ + std::ratio<INTMAX_MAX, INTMAX_MAX> r1 __attribute__((unused)); + std::ratio<-INTMAX_MAX, INTMAX_MAX> r2 __attribute__((unused)); +} + +void +test02() +{ + std::ratio<INTMAX_MIN, 1> r1 __attribute__((unused)); +} + +void +test03() +{ + std::ratio<1, INTMAX_MIN> r1 __attribute__((unused)); +} + +void +test04() +{ + std::ratio<1,0> r1 __attribute__((unused)); +} + +// { dg-error "instantiated from here" "" { target *-*-* } 34 } +// { dg-error "instantiated from here" "" { target *-*-* } 40 } +// { dg-error "instantiated from here" "" { target *-*-* } 46 } +// { dg-error "denominator cannot be zero" "" { target *-*-* } 155 } +// { dg-error "out of range" "" { target *-*-* } 156 } +// { dg-error "overflow in constant expression" "" { target *-*-* } 74 } diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/45866.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/45866.cc new file mode 100644 index 000000000..19735fc3e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/operations/45866.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2010-10-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 Free Software Foundation +// +// 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 <ratio> +#include <testsuite_hooks.h> + +// libstdc++/45866 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::ratio<1, 4>::type r_type1; + typedef std::ratio<3, 2>::type r_type2; + + typedef std::ratio_add<r_type1, r_type2> ra_type; + + VERIFY( ra_type::num == ra_type::type::num ); + VERIFY( ra_type::den == ra_type::type::den ); + VERIFY( ra_type::num == 7 ); + VERIFY( ra_type::den == 4 ); + + typedef std::ratio_subtract<r_type1, r_type2> rs_type; + + VERIFY( rs_type::num == rs_type::type::num ); + VERIFY( rs_type::den == rs_type::type::den ); + VERIFY( rs_type::num == -5 ); + VERIFY( rs_type::den == 4 ); + + typedef std::ratio_multiply<r_type1, r_type2> rm_type; + + VERIFY( rm_type::num == rm_type::type::num ); + VERIFY( rm_type::den == rm_type::type::den ); + VERIFY( rm_type::num == 3 ); + VERIFY( rm_type::den == 8 ); + + typedef std::ratio_divide<r_type1, r_type2> rd_type; + + VERIFY( rd_type::num == rd_type::type::num ); + VERIFY( rd_type::den == rd_type::type::den ); + VERIFY( rd_type::num == 1 ); + VERIFY( rd_type::den == 6 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/47913.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/47913.cc new file mode 100644 index 000000000..4105a710d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/operations/47913.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2011 Free Software Foundation +// +// 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 <ratio> +#include <testsuite_hooks.h> + +// libstdc++/47913 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + const intmax_t m = (intmax_t)1 << (4 * sizeof(intmax_t) - 1); + typedef ratio_add<ratio<1, (m - 1) * (m - 2)>, + ratio<1, (m - 3) * (m - 2)> > ra_type; + + VERIFY( ra_type::num == 2 ); + VERIFY( ra_type::den == (m - 1) * (m - 3) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops1.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops1.cc new file mode 100644 index 000000000..183269e62 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops1.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2008-07-03 Chris Fairles <chris.fairles@gmail.com> + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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 <ratio> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ratio_add<std::ratio<3,8>, std::ratio<5,12>>::type r; + + VERIFY( r.num == 19 ); + VERIFY( r.den == 24 ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + std::ratio_subtract<std::ratio<3,8>, std::ratio<5,12>>::type r; + + VERIFY( r.num == -1 ); + VERIFY( r.den == 24 ); +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + std::ratio_multiply<std::ratio<3,8>, std::ratio<5,12>>::type r; + + VERIFY( r.num == 5 ); + VERIFY( r.den == 32 ); +} + +void +test04() +{ + bool test __attribute__((unused)) = true; + std::ratio_divide<std::ratio<3,8>, std::ratio<5,12>>::type r; + + VERIFY( r.num == 9 ); + VERIFY( r.den == 10 ); +} + +int main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops2.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops2.cc new file mode 100644 index 000000000..abd2e7556 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops2.cc @@ -0,0 +1,72 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2008-07-03 Chris Fairles <chris.fairles@gmail.com> + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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 <ratio> +#include <testsuite_hooks.h> + +typedef std::ratio<1, INTMAX_MAX> one_over_max; +typedef std::ratio<2, INTMAX_MAX> two_over_max; +typedef std::ratio<INTMAX_MAX, 1> max_over_one; +typedef std::ratio<INTMAX_MAX, 2> max_over_two; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ratio_add<one_over_max, one_over_max>::type r1; + + VERIFY( r1.num == two_over_max::num); + VERIFY( r1.den == two_over_max::den); + + std::ratio_add< + std::ratio<INTMAX_MAX / 2, INTMAX_MAX / 2>, + std::ratio<INTMAX_MAX / 2 , INTMAX_MAX / 2 + 1>>::type r2; + + VERIFY( r2.num == INTMAX_MAX ); + VERIFY( r2.den == (INTMAX_MAX / 2) + 1 ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::ratio_subtract<one_over_max, one_over_max>::type r1; + + VERIFY( r1.num == 0); + VERIFY( r1.den == 1); + + std::ratio_subtract< + std::ratio<INTMAX_MAX / 2, INTMAX_MAX / 2>, + std::ratio<INTMAX_MAX / 2 , INTMAX_MAX / 2 + 1>>::type r2; + + VERIFY( r2.num == 1 ); + VERIFY( r2.den == (INTMAX_MAX / 2) + 1 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops3.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops3.cc new file mode 100644 index 000000000..fde9fb9dd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops3.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2008-07-03 Chris Fairles <chris.fairles@gmail.com> + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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 <ratio> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ratio_multiply< + std::ratio<2, INTMAX_MAX>, + std::ratio<INTMAX_MAX, 2>>::type r1; + + VERIFY( r1.num == 1 ); + VERIFY( r1.den == 1 ); + + std::ratio_multiply< + std::ratio<INTMAX_MAX, 2>, + std::ratio<2 , INTMAX_MAX - 1>>::type r2; + + VERIFY( r2.num == INTMAX_MAX ); + VERIFY( r2.den == INTMAX_MAX - 1 ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::ratio_divide< + std::ratio<INTMAX_MAX, 2>, + std::ratio<INTMAX_MAX, 2>>::type r1; + + VERIFY( r1.num == 1 ); + VERIFY( r1.den == 1 ); + + std::ratio_divide< + std::ratio<INTMAX_MAX-1, 2>, + std::ratio<INTMAX_MAX, 2>>::type r2; + + VERIFY( r2.num == INTMAX_MAX - 1 ); + VERIFY( r2.den == INTMAX_MAX ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc new file mode 100644 index 000000000..b7076dfc5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc @@ -0,0 +1,47 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2008-07-03 Chris Fairles <chris.fairles@gmail.com> + +// Copyright (C) 2008, 2009, 2011 Free Software Foundation +// +// 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 <ratio> + +void +test01() +{ + std::ratio_add<std::ratio<INTMAX_MAX, 1>, std::ratio<1>>::type r1; +} + +void +test02() +{ + std::ratio_multiply<std::ratio<-INTMAX_MAX, 2>, std::ratio<3, 2>>::type r1; + std::ratio_multiply<std::ratio<INTMAX_MAX>, std::ratio<INTMAX_MAX>>::type r2; +} + +// { dg-error "instantiated from here" "" { target *-*-* } 29 } +// { dg-error "instantiated from here" "" { target *-*-* } 35 } +// { dg-error "instantiated from here" "" { target *-*-* } 36 } +// { dg-error "overflow in addition" "" { target *-*-* } 132 } +// { dg-error "overflow in multiplication" "" { target *-*-* } 104 } +// { dg-error "overflow in multiplication" "" { target *-*-* } 100 } +// { dg-error "overflow in multiplication" "" { target *-*-* } 102 } +// { dg-excess-errors "In instantiation of" } +// { dg-excess-errors "out of range" } diff --git a/libstdc++-v3/testsuite/20_util/ratio/requirements/constexpr_data.cc b/libstdc++-v3/testsuite/20_util/ratio/requirements/constexpr_data.cc new file mode 100644 index 000000000..d3a1543de --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/ratio/requirements/constexpr_data.cc @@ -0,0 +1,60 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <ratio> +#include <testsuite_common_types.h> + +namespace __gnu_test +{ + struct constexpr_member_data + { + template<typename _Ttesttype> + void + operator()() + { + struct _Concept + { + void __constraint() + { + constexpr intmax_t v1 __attribute__((unused)) + = _Ttesttype::num; + constexpr intmax_t v2 __attribute__((unused)) + = _Ttesttype::den; + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + __gnu_test::constexpr_member_data test; + typedef std::ratio<600, 900> R1; + typedef std::ratio<700, 200> R2; + test.operator()<R1>(); + test.operator()<std::ratio_add<R1, R2>>(); + test.operator()<std::ratio_subtract<R1, R2>>(); + test.operator()<std::ratio_multiply<R1, R2>>(); + test.operator()<std::ratio_divide<R1, R2>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/raw_storage_iterator/requirements/base_classes.cc b/libstdc++-v3/testsuite/20_util/raw_storage_iterator/requirements/base_classes.cc new file mode 100644 index 000000000..865e2885a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/raw_storage_iterator/requirements/base_classes.cc @@ -0,0 +1,36 @@ +// { dg-do compile } + +// 2001-06-18 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003, 2007, 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/>. + +// 20.4.2 raw storage iterator + +#include <memory> + +void test01() +{ + using namespace std; + + // Check for required base class. + long l; + typedef raw_storage_iterator<long*, long> test_iterator; + typedef iterator<output_iterator_tag, void, void, void, void> base_iterator; + test_iterator rs_it(&l); + base_iterator* base __attribute__((unused)) = &rs_it; +} diff --git a/libstdc++-v3/testsuite/20_util/raw_storage_iterator/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/20_util/raw_storage_iterator/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..906954681 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/raw_storage_iterator/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <memory> + +template class std::raw_storage_iterator<int*, int>; diff --git a/libstdc++-v3/testsuite/20_util/raw_storage_iterator/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/raw_storage_iterator/requirements/typedefs.cc new file mode 100644 index 000000000..a62bde782 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/raw_storage_iterator/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// 2001-06-18 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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/>. + +// 20.4.2 raw storage iterator + +#include <memory> + +void test01() +{ + using namespace std; + + // Check for required typedefs + typedef raw_storage_iterator<long*, long> test_iterator; + typedef test_iterator::value_type value_type; + typedef test_iterator::difference_type difference_type; + typedef test_iterator::pointer pointer; + typedef test_iterator::reference reference; + typedef test_iterator::iterator_category iteratory_category; +} diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/24803.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/24803.cc new file mode 100644 index 000000000..4bf61485c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/24803.cc @@ -0,0 +1,80 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2008, 2009, 2010, 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/>. + + +#include <functional> + +struct test_type +{ + int member(); + int cmember()const; + int member2(char); + int cmember2(char)const; +}; + +struct functor1 : public std::unary_function<int, double> +{ + double operator()(int) const; +}; + +struct functor2 : public std::binary_function<int, char, double> +{ + double operator()(int, char) const; +}; + +template <class T> +void verify_return_type(T, T) +{ +} + +void test01() +{ + test_type* null_tt = 0; + const test_type* null_ttc = 0; + int zero; + + std::reference_wrapper<double (int)>* pr1(0); + verify_return_type((*pr1)(0), double()); + std::reference_wrapper<double (*)(int)>* pr2(0); + verify_return_type((*pr2)(0), double()); + std::reference_wrapper<int (test_type::*)()>* pr3(0); + verify_return_type((*pr3)(null_tt), int()); + std::reference_wrapper<int (test_type::*)()const>* pr4(0); + verify_return_type((*pr4)(null_ttc), int()); + std::reference_wrapper<functor1>* pr5(0); + + // libstdc++/24803 + verify_return_type((*pr5)(0), double()); + verify_return_type((*pr5)(zero), double()); + + std::reference_wrapper<double (int, char)>* pr1b(0); + verify_return_type((*pr1b)(0, 0), double()); + std::reference_wrapper<double (*)(int, char)>* pr2b(0); + verify_return_type((*pr2b)(0, 0), double()); + std::reference_wrapper<int (test_type::*)(char)>* pr3b(0); + verify_return_type((*pr3b)(null_tt,zero), int()); + std::reference_wrapper<int (test_type::*)()const>* pr4b(0); + verify_return_type((*pr4b)(null_ttc), int()); + std::reference_wrapper<functor2>* pr5b(0); + + // libstdc++/24803 + verify_return_type((*pr5b)(0, 0), double()); + verify_return_type((*pr5b)(zero, zero), double()); +} diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/41792.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/41792.cc new file mode 100644 index 000000000..b167d7122 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/41792.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-05-20 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 <functional> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// libstdc++/41792 +void test01() +{ + using namespace __gnu_test; + + OverloadedAddress* ao1 = new OverloadedAddress(); + std::reference_wrapper<OverloadedAddress> rw1(*ao1); +} diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-2.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-2.cc new file mode 100644 index 000000000..c1b62932f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-2.cc @@ -0,0 +1,46 @@ +// { 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.6.4 function object return types [func.ret] +#include <functional> + +struct X +{ + int f(int) { return 0; } + int i; +}; + +void test01() +{ + typedef int (X::*mfp)(int); + typedef int X::*mp; + mfp m = &X::f; + mp m2 = &X::i; + X x = { }; + std::ref(m)(x, 1); + std::ref(m)(&x, 1); + int& i1 = std::ref(m2)(x); + int& i2 = std::ref(m2)(&x); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke.cc new file mode 100644 index 000000000..7b694c764 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke.cc @@ -0,0 +1,120 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009, 2010, 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/>. + +#include <functional> +#include <type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +struct X +{ + typedef int result_type; + + X() : bar(17) {} + + int foo(float x) { return truncate_float(x); } + int foo_c(float x) const { return truncate_float(x); } + int foo_v(float x) volatile { return truncate_float(x); } + int foo_cv(float x) const volatile { return truncate_float(x); } + int foo_varargs(float x, ...) { return truncate_float(x); } + + int operator()(float x) + { + return foo(x) + 1; + } + + int operator()(float x) const + { + return foo_c(x) + 2; + } + + int bar; + + private: + X(const X&); + X& operator=(const X&); +}; + +int seventeen() { return 17; } + +struct get_seventeen +{ + typedef int result_type; + int operator()() const { return 17; } +}; + +void test01() +{ + using std::ref; + using std::cref; + + ::get_seventeen get_sev; + ::X x; + ::X* xp = &x; + int (::X::* p_foo)(float) = &::X::foo; + int (::X::* p_foo_c)(float) const = &::X::foo_c; + int (::X::* p_foo_v)(float) volatile = &::X::foo_v; + int (::X::* p_foo_cv)(float) const volatile = &::X::foo_cv; + int (::X::* p_foo_varargs)(float, ...) = &::X::foo_varargs; + int ::X::* p_bar = &::X::bar; + + const float pi = 3.14; + + // Functions + VERIFY(ref(truncate_float)(pi) == 3); + VERIFY(ref(seventeen)() == 17); + + // Function pointers + VERIFY(cref(truncate_float)(pi) == 3); + VERIFY(cref(seventeen)() == 17); + + // Member function pointers + VERIFY(ref(p_foo)(x, pi) == 3); + VERIFY(ref(p_foo)(xp, pi) == 3); + VERIFY(ref(p_foo_c)(x, pi) == 3); + VERIFY(ref(p_foo_c)(xp, pi) == 3); + VERIFY(ref(p_foo_v)(x, pi) == 3); + VERIFY(ref(p_foo_v)(xp, pi) == 3); + VERIFY(ref(p_foo_cv)(x, pi) == 3); + VERIFY(ref(p_foo_cv)(xp, pi) == 3); + // VERIFY(ref(p_foo_varargs)(x, pi) == 3); + // VERIFY(ref(p_foo_varargs)(xp, pi, 1, 1) == 3); + // VERIFY(ref(p_foo_varargs)(x, pi, 1, 1) == 3); + // VERIFY(ref(p_foo_varargs)(xp, pi) == 3); + + // Member data pointers + VERIFY(ref(p_bar)(x) == 17); + VERIFY(ref(p_bar)(xp) == 17); + + // Function objects + VERIFY(ref(get_sev)() == 17); + VERIFY(cref(get_sev)() == 17); + VERIFY(ref(x)(pi) == 4); + VERIFY(cref(x)(pi) == 5); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/ref_neg.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/ref_neg.cc new file mode 100644 index 000000000..947a9b02f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/ref_neg.cc @@ -0,0 +1,44 @@ +// 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.8.3 Class template reference_wrapper + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <functional> + +struct X { }; +X rval(); +X&& rvalref(); + +void test01() +{ + std::ref(1); // { dg-error "deleted" } + std::cref(1); // { dg-error "deleted" } + std::ref( int() ); // { dg-error "deleted" } + std::cref( int() ); // { dg-error "deleted" } + std::ref(rval()); // { dg-error "deleted" } + std::cref(rvalref()); // { dg-error "deleted" } +} + +int main() +{ + test02(); +} + +// { dg-excess-errors "" } diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/result_type.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/result_type.cc new file mode 100644 index 000000000..911e9a944 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/result_type.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-10-06 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 <functional> + +using namespace std; + +struct T; + +reference_wrapper<int(float, ...)>::result_type i01; +reference_wrapper<int(float, ...) const>::result_type i02; +reference_wrapper<int(float, ...) volatile>::result_type i03; +reference_wrapper<int(float, ...) const volatile>::result_type i04; + +reference_wrapper<int(*)(float, ...)>::result_type i05; +reference_wrapper<int(* const)(float, ...)>::result_type i06; +reference_wrapper<int(* volatile)(float, ...)>::result_type i07; +reference_wrapper<int(* const volatile)(float, ...)>::result_type i08; + +reference_wrapper<int(T::*)(float, ...)>::result_type i09; +reference_wrapper<int(T::*)(float, ...) const>::result_type i10; +reference_wrapper<int(T::*)(float, ...) volatile>::result_type i11; +reference_wrapper<int(T::*)(float, ...) const volatile>::result_type i12; diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs-2.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs-2.cc new file mode 100644 index 000000000..8b1b7e3f1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs-2.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-10-06 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 <functional> + +using namespace std; + +reference_wrapper<int(float)>::argument_type i01; +reference_wrapper<int(float) const>::argument_type i02; +reference_wrapper<int(float) volatile>::argument_type i03; +reference_wrapper<int(float) const volatile>::argument_type i04; +reference_wrapper<int(float)>::result_type i05; +reference_wrapper<int(float) const>::result_type i06; +reference_wrapper<int(float) volatile>::result_type i07; +reference_wrapper<int(float) const volatile>::result_type i08; + +reference_wrapper<int(*)(float)>::argument_type i09; +reference_wrapper<int(* const)(float)>::argument_type i10; +reference_wrapper<int(* volatile)(float)>::argument_type i11; +reference_wrapper<int(* const volatile)(float)>::argument_type i12; +reference_wrapper<int(*)(float)>::result_type i13; +reference_wrapper<int(* const)(float)>::result_type i14; +reference_wrapper<int(* volatile)(float)>::result_type i15; +reference_wrapper<int(* const volatile)(float)>::result_type i16; + +reference_wrapper<int(float, char)>::first_argument_type i17; +reference_wrapper<int(float, char) const>::first_argument_type i18; +reference_wrapper<int(float, char) volatile>::first_argument_type i19; +reference_wrapper<int(float, char) const volatile>::first_argument_type i20; +reference_wrapper<int(float, char)>::second_argument_type i21; +reference_wrapper<int(float, char) const>::second_argument_type i22; +reference_wrapper<int(float, char) volatile>::second_argument_type i23; +reference_wrapper<int(float, char) const volatile>::second_argument_type i24; +reference_wrapper<int(float, char)>::result_type i25; +reference_wrapper<int(float, char) const>::result_type i26; +reference_wrapper<int(float, char) volatile>::result_type i27; +reference_wrapper<int(float, char) const volatile>::result_type i28; + +reference_wrapper<int(*)(float, char)>::first_argument_type i29; +reference_wrapper<int(* const)(float, char)>::first_argument_type i30; +reference_wrapper<int(* volatile)(float, char)>::first_argument_type i31; +reference_wrapper<int(* const volatile)(float, char)>::first_argument_type i32; +reference_wrapper<int(*)(float, char)>::second_argument_type i33; +reference_wrapper<int(* const)(float, char)>::second_argument_type i34; +reference_wrapper<int(* volatile)(float, char)>::second_argument_type i35; +reference_wrapper<int(*const volatile)(float, char)>::second_argument_type i36; +reference_wrapper<int(*)(float, char)>::result_type i37; +reference_wrapper<int(* const)(float, char)>::result_type i38; +reference_wrapper<int(* volatile)(float, char)>::result_type i39; +reference_wrapper<int(* const volatile)(float, char)>::result_type i40; diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs-3.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs-3.cc new file mode 100644 index 000000000..2fea52eed --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs-3.cc @@ -0,0 +1,148 @@ +// { 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/>. + +#include <functional> +#include <type_traits> + +struct S { }; + +struct S0 +{ + typedef int argument_type; +}; + +struct S1 +{ + typedef float first_argument_type; +}; + +struct S2 +{ + typedef char second_argument_type; +}; + +struct S01 : S0, S1 { }; +struct S02 : S0, S2 { }; +struct S12 : S1, S2 { }; + +struct S012 : S0, S1, S2 { }; + +using std::__sfinae_types; +using std::integral_constant; +using std::remove_cv; + +_GLIBCXX_HAS_NESTED_TYPE(argument_type) +_GLIBCXX_HAS_NESTED_TYPE(first_argument_type) +_GLIBCXX_HAS_NESTED_TYPE(second_argument_type) + +template<typename T> + struct has_arg_type : __has_argument_type<T> + { }; + +template<typename T> + struct has_1st_arg_type : __has_first_argument_type<T> + { }; + +template<typename T> + struct has_2nd_arg_type : __has_second_argument_type<T> + { }; + +template<typename T, bool = has_arg_type<T>::value> +struct test_arg_type +{ + static_assert( !has_arg_type<std::reference_wrapper<T>>::value, + "reference_wrapper has no nested argument_type"); +}; + +template<typename T> +struct test_arg_type<T, true> +{ + typedef std::reference_wrapper<T> ref; + + static_assert( has_arg_type<ref>::value, + "reference_wrapper has nested argument_type"); + + static_assert( + std::is_same< typename T::argument_type, + typename ref::argument_type >::value, + "reference_wrapper has the correct argument_type"); +}; + +template<typename T, + bool = has_1st_arg_type<T>::value && has_2nd_arg_type<T>::value> +struct test_1st_2nd_arg_types +{ + typedef std::reference_wrapper<T> ref; + + static_assert( !has_1st_arg_type<ref>::value, + "reference_wrapper has no nested first_argument_type"); + + static_assert( !has_2nd_arg_type<ref>::value, + "reference_wrapper has no nested second_argument_type"); +}; + +template<typename T> +struct test_1st_2nd_arg_types<T, true> +{ + typedef std::reference_wrapper<T> ref; + + static_assert( has_1st_arg_type<ref>::value, + "reference_wrapper has nested first_argument_type"); + + static_assert( has_2nd_arg_type<ref>::value, + "reference_wrapper has nested second_argument_type"); + + static_assert( + std::is_same< typename T::first_argument_type, + typename ref::first_argument_type>::value, + "reference_wrapper has correct first_argument_type"); + + static_assert( + std::is_same< typename T::second_argument_type, + typename ref::second_argument_type>::value, + "reference_wrapper has correct second_argument_type"); +}; + + +template<typename T> + void test() + { + test_arg_type<T> t; + test_arg_type<const T> tc; + test_arg_type<volatile T> tv; + test_arg_type<const volatile T> tcv; + test_1st_2nd_arg_types<T> t12; + test_1st_2nd_arg_types<const T> t12c; + test_1st_2nd_arg_types<volatile T> t12v; + test_1st_2nd_arg_types<const volatile T> t12cv; + } + +int main() +{ + test<S>(); + test<S0>(); + test<S1>(); + test<S2>(); + test<S01>(); + test<S02>(); + test<S12>(); + test<S012>(); +} + diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs.cc new file mode 100644 index 000000000..815700f1c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/typedefs.cc @@ -0,0 +1,59 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009, 2010, 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/>. + +#include <functional> +#include <type_traits> + +struct X {}; + +struct int_result_type { typedef int result_type; }; + +struct derives_unary : std::unary_function<int, int> {}; + +struct derives_binary : std::binary_function<int, float, int> {}; + +struct derives_unary_binary + : std::unary_function<int, int>, + std::binary_function<int, float, int> +{ + typedef int result_type; +}; + +void test01() +{ + using std::reference_wrapper; + using std::is_same; + + // Check result_type typedef + static_assert( is_same<reference_wrapper<int_result_type>::result_type, int>::value, "has result_type" ); + static_assert( is_same<reference_wrapper<derives_unary>::result_type, int>::value, "has result_type" ); + static_assert( is_same<reference_wrapper<derives_binary>::result_type, int>::value, "has result_type" ); + static_assert( is_same<reference_wrapper<derives_unary_binary>::result_type, int>::value, "has result_type" ); + static_assert( is_same<reference_wrapper<int(void)>::result_type, int>::value, "has result_type" ); + static_assert( is_same<reference_wrapper<int(*)(void)>::result_type, int>::value, "has result_type" ); + static_assert( is_same<reference_wrapper<int (::X::*)()>::result_type, int>::value, "has result_type" ); + static_assert( is_same<reference_wrapper<int (::X::*)(float)>::result_type, int>::value, "has result_type" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/rel_ops.cc b/libstdc++-v3/testsuite/20_util/rel_ops.cc new file mode 100644 index 000000000..534b4b626 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/rel_ops.cc @@ -0,0 +1,45 @@ +// 2002-04-13 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2002, 2004, 2005, 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/>. + +// 20.2.1 Operators + +#include <utility> +#include <vector> + +using namespace std::rel_ops; + +// libstdc++/3628 +void test01() +{ + std::vector<int> v; + std::vector<int>::iterator vi; + v.push_back(1); + vi = v.end(); + vi != v.begin(); + vi > v.begin(); + vi <= v.begin(); + vi >= v.begin(); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/20_util/remove_reference/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/remove_reference/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..aeffd5a0f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/remove_reference/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include <type_traits> + +namespace std +{ + typedef short test_type; + template struct remove_reference<test_type>; +} diff --git a/libstdc++-v3/testsuite/20_util/remove_reference/value.cc b/libstdc++-v3/testsuite/20_util/remove_reference/value.cc new file mode 100644 index 000000000..a412303d0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/remove_reference/value.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } +// 2007-06-02 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2007, 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> +#include <testsuite_tr1.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::remove_reference; + using std::is_same; + using namespace __gnu_test; + + VERIFY( (is_same<remove_reference<int&>::type, int>::value) ); + VERIFY( (is_same<remove_reference<int>::type, int>::value) ); + VERIFY( (is_same<remove_reference<const int&>::type, const int>::value) ); + VERIFY( (is_same<remove_reference<int*&>::type, int*>::value) ); + VERIFY( (is_same<remove_reference<ClassType&>::type, ClassType>::value) ); + VERIFY( (is_same<remove_reference<ClassType>::type, ClassType>::value) ); + VERIFY( (is_same<remove_reference<int(&)(int)>::type, int(int)>::value) ); + VERIFY( (is_same<remove_reference<int&&>::type, int>::value) ); + VERIFY( (is_same<remove_reference<int>::type, int>::value) ); + VERIFY( (is_same<remove_reference<const int&&>::type, const int>::value) ); + VERIFY( (is_same<remove_reference<int*&&>::type, int*>::value) ); + VERIFY( (is_same<remove_reference<ClassType&&>::type, ClassType>::value) ); + VERIFY( (is_same<remove_reference<ClassType>::type, ClassType>::value) ); + VERIFY( (is_same<remove_reference<int(&&)(int)>::type, int(int)>::value) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/assign.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/assign.cc new file mode 100644 index 000000000..7c93eb077 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/assign.cc @@ -0,0 +1,72 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + } +}; + + +// 20.6.6.2.3 shared_ptr assignment [util.smartptr.shared.assign] + +// Assignment from shared_ptr<Y> +void +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + + a = std::shared_ptr<A>(new A); + VERIFY( a.get() != 0 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + + a = std::shared_ptr<A>(); + VERIFY( a.get() == 0 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 1 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/auto_ptr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/auto_ptr.cc new file mode 100644 index 000000000..e2ec07860 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/auto_ptr.cc @@ -0,0 +1,85 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + + +// 20.6.6.2.3 shared_ptr assignment [util.smartptr.shared.assign] + +// Assignment from auto_ptr<Y> +int +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a(new A); + std::auto_ptr<B> b(new B); + a = std::move(b); + VERIFY( a.get() != 0 ); + VERIFY( b.get() == 0 ); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 1 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc new file mode 100644 index 000000000..b79a25b13 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; +struct B { }; + +// 20.6.6.2.3 shared_ptr assignment [util.smartptr.shared.assign] + +// Assignment from incompatible auto_ptr<Y> +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + std::auto_ptr<B> b; + a = std::move(b); // { dg-error "here" } + + return 0; +} + +int +main() +{ + test01(); + return 0; +} +// { dg-excess-errors "In constructor" } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/auto_ptr_rvalue.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/auto_ptr_rvalue.cc new file mode 100644 index 000000000..376e8945f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/auto_ptr_rvalue.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x -Wno-deprecated" } +// { dg-do compile } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.7.12.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; +std::auto_ptr<A> source() { return std::auto_ptr<A>(); } + +// 20.7.12.2.3 shared_ptr assignment [util.smartptr.shared.assign] + +// Assignment from rvalue auto_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + a = source(); + + return 0; +} + +int +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + std::auto_ptr<A> au; + a = std::move(au); + + return 0; +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/dr541.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/dr541.cc new file mode 100644 index 000000000..48ddf9053 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/dr541.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> + +// DR 541. shared_ptr template assignment and void +void test01() +{ + std::shared_ptr<void> p; + p.operator=<void>(p); +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/move.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/move.cc new file mode 100644 index 000000000..1a7b20caf --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/move.cc @@ -0,0 +1,118 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <utility> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Rvalue assignment from shared_ptr +void +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a1; + std::shared_ptr<A> a2(new A); + + a1 = std::move(a2); + VERIFY( a1.get() != 0 ); + VERIFY( a2.get() == 0 ); + VERIFY( a1.use_count() == 1 ); + VERIFY( a2.use_count() == 0 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + + a1 = std::move(std::shared_ptr<A>()); + VERIFY( a1.get() == 0 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 1 ); +} + +// Rvalue assignment from shared_ptr<Y> +void +test02() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + std::shared_ptr<B> b(new B); + + a = std::move(b); + VERIFY( a.get() != 0 ); + VERIFY( b.get() == 0 ); + VERIFY( a.use_count() == 1 ); + VERIFY( b.use_count() == 0 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + a = std::move(std::shared_ptr<A>()); + VERIFY( a.get() == 0 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 1 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 1 ); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/shared_ptr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/shared_ptr.cc new file mode 100644 index 000000000..4543be696 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/shared_ptr.cc @@ -0,0 +1,96 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + + +// 20.6.6.2.3 shared_ptr assignment [util.smartptr.shared.assign] + +// Assignment from shared_ptr<Y> +void +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + + a = std::shared_ptr<A>(); + VERIFY( a.get() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + a = std::shared_ptr<A>(new A); + VERIFY( a.get() != 0 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + a = std::shared_ptr<B>(new B); + VERIFY( a.get() != 0 ); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 1 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/shared_ptr_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/shared_ptr_neg.cc new file mode 100644 index 000000000..e0d09dee9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/shared_ptr_neg.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; +struct B { }; + +// 20.6.6.2.3 shared_ptr assignment [util.smartptr.shared.assign] + +// Assignment from incompatible shared_ptr<Y> +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + std::shared_ptr<B> b; + a = b; // { dg-error "here" } + + return 0; +} + +int +main() +{ + test01(); + return 0; +} +// { dg-error "In member function" "" { target *-*-* } 0 } +// { dg-error "cannot convert" "" { target *-*-* } 0 } +// { dg-error "instantiated from" "" { target *-*-* } 0 } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/unique_ptr_lvalue_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/unique_ptr_lvalue_neg.cc new file mode 100644 index 000000000..dae967bfd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/unique_ptr_lvalue_neg.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2008, 2009, 2010 Free Software Foundation +// +// 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.7.12.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.7.12.2.3 shared_ptr assignment [util.smartptr.shared.assign] + +// Assignment from lvalue unique_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + std::unique_ptr<A> u; + a = u; // { dg-error "cannot bind" } + + return 0; +} + +int +main() +{ + test01(); + return 0; +} +// { dg-excess-errors "initializing argument" } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/assign/unique_ptr_rvalue.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/unique_ptr_rvalue.cc new file mode 100644 index 000000000..e759a42c3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/assign/unique_ptr_rvalue.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.7.12.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; +std::unique_ptr<A> source() { return std::unique_ptr<A>(); } + +// 20.7.12.2.3 shared_ptr assignment [util.smartptr.shared.assign] + +// Assignment from rvalue unique_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + a = source(); + + return 0; +} + +int +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + std::unique_ptr<A> u; + a = std::move(u); + + return 0; +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/casts/1.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/casts/1.cc new file mode 100644 index 000000000..a12c54964 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/casts/1.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2.10 shared_ptr casts [util.smartptr.shared.cast] + +#include <memory> +#include <testsuite_tr1.h> + +// { dg-do compile } + +struct MyP { virtual ~MyP() { }; }; +struct MyDP : MyP { }; + +int main() +{ + using __gnu_test::check_ret_type; + using std::shared_ptr; + using std::static_pointer_cast; + using std::const_pointer_cast; + using std::dynamic_pointer_cast; + + shared_ptr<double> spd; + shared_ptr<const int> spci; + shared_ptr<MyP> spa; + + check_ret_type<shared_ptr<void> >(static_pointer_cast<void>(spd)); + check_ret_type<shared_ptr<int> >(const_pointer_cast<int>(spci)); + check_ret_type<shared_ptr<MyDP> >(static_pointer_cast<MyDP>(spa)); +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/42925.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/42925.cc new file mode 100644 index 000000000..41e09d666 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/42925.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.11.2 Class template shared_ptr [util.smartptr.shared] + +#include <memory> + +// libstdc++/42925 (also see GB 99) +void test01() +{ + std::shared_ptr<int> ptr; + if (ptr == 0) + { } + if (0 == ptr) + { } + if (ptr != 0) + { } + if (0 != ptr) + { } +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/cmp.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/cmp.cc new file mode 100644 index 000000000..ba8280716 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/cmp.cc @@ -0,0 +1,88 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + virtual ~A() { } +}; + +struct B : A +{ +}; + +// 20.6.6.2.6 shared_ptr comparison [util.smartptr.shared.cmp] + +int +test01() +{ + bool test __attribute__((unused)) = true; + + // test empty shared_ptrs compare equivalent + std::shared_ptr<A> p1; + std::shared_ptr<B> p2; + VERIFY( p1 == p2 ); + VERIFY( !(p1 != p2) ); + VERIFY( !(p1 < p2) && !(p2 < p1) ); + return 0; +} + + +// Construction from pointer +int +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> A_default; + + std::shared_ptr<A> A_from_A(new A); + VERIFY( A_default != A_from_A ); + VERIFY( !(A_default == A_from_A) ); + VERIFY( (A_default < A_from_A) || (A_from_A < A_default) ); + + std::shared_ptr<B> B_from_B(new B); + VERIFY( B_from_B != A_from_A ); + VERIFY( !(B_from_B == A_from_A) ); + VERIFY( (B_from_B < A_from_A) || (A_from_A < B_from_B) ); + + A_from_A.reset(); + VERIFY( A_default == A_from_A ); + VERIFY( !(A_default != A_from_A) ); + VERIFY( !(A_default < A_from_A) && !(A_from_A < A_default) ); + + B_from_B.reset(); + VERIFY( B_from_B == A_from_A ); + VERIFY( !(B_from_B != A_from_A) ); + VERIFY( !(B_from_B < A_from_A) && !(A_from_A < B_from_B) ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/less.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/less.cc new file mode 100644 index 000000000..b51b222a0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/comparison/less.cc @@ -0,0 +1,102 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.13.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +namespace std +{ + template<> + struct less<A*> : binary_function<A*,A*,bool> + { + static int count; + bool operator()(A* l, A* r) { ++count; return l < r; } + }; + int less<A*>::count = 0; +} + +// 20.8.13.2.7 shared_ptr comparison [util.smartptr.shared.cmp] + + +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::less<std::shared_ptr<A>> less; + // test empty shared_ptrs compare equivalent + std::shared_ptr<A> p1; + std::shared_ptr<A> p2; + VERIFY( !less(p1, p2) && !less(p2, p1) ); + VERIFY( std::less<A*>::count == 2 ); + return 0; +} + + +// Construction from pointer +int +test02() +{ + bool test __attribute__((unused)) = true; + + std::less<std::shared_ptr<A>> less; + + std::shared_ptr<A> empty; + std::shared_ptr<A> p1(new A); + std::shared_ptr<A> p2(new A); + + VERIFY( less(p1, p2) || less(p2, p1) ); + VERIFY( !(less(p1, p2) && less(p2, p1)) ); + + p1.reset(); + VERIFY( !less(p1, empty) && !less(empty, p1) ); + + p2.reset(); + VERIFY( !less(p1, p2) && !less(p2, p1) ); + + return 0; +} + +// Aliasing +int +test03() +{ + bool test __attribute__((unused)) = true; + + std::less<std::shared_ptr<A>> less; + + A a; + std::shared_ptr<A> p1(new A); + std::shared_ptr<A> p2(p1, &a); + VERIFY( less(p1, p2) || less(p2, p1) ); + + return 0; +} +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/39405.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/39405.cc new file mode 100644 index 000000000..d5b3f7dea --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/39405.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2009 Free Software Foundation +// +// 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> + +// libstdc++/39405 +template<typename T> + struct foo + { + std::shared_ptr<foo<T> > m_foo; + }; + +std::shared_ptr<foo<int> > t; diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc new file mode 100644 index 000000000..f5899d399 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010, 2011 Free Software Foundation +// +// 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.9.11.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> + +// incomplete type +struct X; + +// get an auto_ptr rvalue +std::auto_ptr<X>&& ap(); + +void test01() +{ + X* px = 0; + std::shared_ptr<X> p1(px); // { dg-error "here" } + // { dg-error "incomplete" "" { target *-*-* } 766 } + + std::shared_ptr<X> p9(ap()); // { dg-error "here" } + // { dg-error "incomplete" "" { target *-*-* } 859 } + +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/46910.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/46910.cc new file mode 100644 index 000000000..d8275198c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/46910.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.10.2 Class template shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +// 20.9.10.2.1 shared_ptr constructors [util.smartptr.shared.const] + +struct deleter; + +class A +{ + ~A() = default; + friend struct deleter; +}; + +struct deleter +{ + void operator()(A* a) const; +}; + +void +test01() +{ + std::shared_ptr<A> p(new A, deleter()); +} + diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias.cc new file mode 100644 index 000000000..9c39ed50d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alias.cc @@ -0,0 +1,107 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() : i() { } + virtual ~A() { } + int i; +}; + +struct B : A +{ + B() : A(), a() { } + virtual ~B() { } + A a; +}; + +void deletefunc(A* p) { delete p; } + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Aliasing constructors + +int test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + std::shared_ptr<bool> b1(a, &test); + VERIFY( b1.use_count() == 0 ); + VERIFY( a.get() == 0 ); + VERIFY( b1.get() == &test ); + + std::shared_ptr<bool> b2(b1); + VERIFY( b2.use_count() == 0 ); + VERIFY( b1.get() == b2.get() ); + + return 0; +} + +int +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a(new A); + std::shared_ptr<int> i1(a, &a->i); + VERIFY( i1.use_count() == 2 ); + + std::shared_ptr<int> i2(i1); + VERIFY( i2.use_count() == 3 ); + VERIFY( i2.get() == &a->i ); + + return 0; +} + +int +test03() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<B> b(new B); + std::shared_ptr<A> a1(b, b.get()); + std::shared_ptr<A> a2(b, &b->a); + VERIFY( a2.use_count() == 3 ); + VERIFY( a1 == b ); + VERIFY( a2 != b ); + VERIFY( a1.get() != a2.get() ); + + std::shared_ptr<A> a3(a1); + VERIFY( a3 == b ); + + a3 = a2; + VERIFY( a3.get() == &b->a ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alloc.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alloc.cc new file mode 100644 index 000000000..4a4be9a68 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/alloc.cc @@ -0,0 +1,103 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using __gnu_test::tracker_allocator_counter; +using __gnu_test::tracker_allocator; + +struct A { }; +void deletefunc(A* p) { delete p; } +struct D +{ + void operator()(A* p) { delete p; ++delete_count; } + static long delete_count; +}; +long D::delete_count = 0; + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction with allocator +int +test01() +{ + bool test __attribute__((unused)) = true; + tracker_allocator_counter::reset(); + + std::shared_ptr<A> p1(new A, deletefunc, tracker_allocator<A>()); + std::size_t const sz = tracker_allocator_counter::get_allocation_count(); + VERIFY( sz > 0 ); + { + std::shared_ptr<A> p2(p1); + VERIFY( p2.use_count() == 2 ); + VERIFY( tracker_allocator_counter::get_allocation_count() == sz ); + VERIFY( tracker_allocator_counter::get_deallocation_count() == 0 ); + } + VERIFY( p1.use_count() == 1 ); + VERIFY( tracker_allocator_counter::get_allocation_count() == sz ); + VERIFY( tracker_allocator_counter::get_deallocation_count() == 0 ); + p1.reset(); + VERIFY( p1.use_count() == 0 ); + VERIFY( tracker_allocator_counter::get_allocation_count() == sz ); + VERIFY( tracker_allocator_counter::get_deallocation_count() == sz ); + + return 0; +} + +// Construction with allocator +int +test02() +{ + bool test __attribute__((unused)) = true; + tracker_allocator_counter::reset(); + + std::shared_ptr<A> p1(new A, deletefunc, tracker_allocator<A>()); + std::size_t const sz1 = tracker_allocator_counter::get_allocation_count(); + VERIFY( sz1 > 0 ); + std::shared_ptr<A> p2(new A, D(), tracker_allocator<A>()); + std::size_t const sz2 = tracker_allocator_counter::get_allocation_count(); + VERIFY( sz2 > sz1 ); + VERIFY( tracker_allocator_counter::get_deallocation_count() == 0 ); + p1 = p2; + VERIFY( p2.use_count() == 2 ); + VERIFY( tracker_allocator_counter::get_allocation_count() == sz2 ); + VERIFY( tracker_allocator_counter::get_deallocation_count() == sz1 ); + p1.reset(); + VERIFY( p2.use_count() == 1 ); + VERIFY( tracker_allocator_counter::get_allocation_count() == sz2 ); + VERIFY( tracker_allocator_counter::get_deallocation_count() == sz1 ); + p2.reset(); + VERIFY( tracker_allocator_counter::get_allocation_count() == sz2 ); + VERIFY( tracker_allocator_counter::get_deallocation_count() == sz2 ); + VERIFY( D::delete_count == 1 ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr.cc new file mode 100644 index 000000000..eb5bb9590 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from auto_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::auto_ptr<A> a(new A); + std::shared_ptr<A> a2(std::move(a)); + VERIFY( a.get() == 0 ); + VERIFY( a2.get() != 0 ); + VERIFY( a2.use_count() == 1 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc new file mode 100644 index 000000000..b078a7df7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> + +struct A { }; + +// 20.6.6.2.3 shared_ptr assignment [util.smartptr.shared.const] + +// Construction from const auto_ptr +void +test01() +{ + const std::auto_ptr<A> a; + std::shared_ptr<A> p(std::move(a)); // { dg-error "no match" } +} +// { dg-excess-errors "candidates are" } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/constexpr.cc new file mode 100644 index 000000000..5a1fc818f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/constexpr.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x -fno-inline -save-temps -g0" } +// { dg-final { scan-assembler-not "_ZNSt10shared_ptrIiEC2Ev" } } +// { dg-final { scan-assembler-not "_ZNSt10shared_ptrIiEC2EDn" } } + +// 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_common_types.h> + +int main() +{ + __gnu_test::constexpr_default_constructible test1; //not literal + test1.operator()<std::shared_ptr<int>>(); + + __gnu_test::constexpr_single_value_constructible test2; //not literal + test2.operator()<std::shared_ptr<int>, std::nullptr_t>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/copy.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/copy.cc new file mode 100644 index 000000000..c5dcffea0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/copy.cc @@ -0,0 +1,136 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + +void deleter(A* p) { delete p; } + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Copy construction +int test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a1; + std::shared_ptr<A> a2(a1); + VERIFY( a2.use_count() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test02() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a1(new A); + std::shared_ptr<A> a2(a1); + VERIFY( a2.use_count() == 2 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test03() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<B> b(new B); + std::shared_ptr<A> a(b); + VERIFY( a.use_count() == 2 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test04() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<B> b(new B, &deleter); + std::shared_ptr<A> a(b); + VERIFY( a.use_count() == 2 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/default.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/default.cc new file mode 100644 index 000000000..ec4c1fdab --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Default construction +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + VERIFY( a.get() == 0 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/move.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/move.cc new file mode 100644 index 000000000..795155829 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/move.cc @@ -0,0 +1,164 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2009 Free Software Foundation +// +// 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/>. + +// TR1 20.6.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <utility> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + +struct D +{ + void operator()(B* p) const { delete p; ++delete_count; } + static long delete_count; +}; +long D::delete_count = 0; + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + D::delete_count = 0; + } +}; + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Rvalue construction +int test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a1; + std::shared_ptr<A> a2(std::move(a1)); + VERIFY( a1.use_count() == 0 ); + VERIFY( a2.use_count() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test02() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a1(new A); + std::shared_ptr<A> a2(std::move(a1)); + VERIFY( a1.use_count() == 0 ); + VERIFY( a2.use_count() == 1 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + + return 0; +} + +int +test03() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<B> b(new B); + std::shared_ptr<A> a(std::move(b)); + VERIFY( b.use_count() == 0 ); + VERIFY( a.use_count() == 1 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test04() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<B> b(new B, D()); + std::shared_ptr<A> a(std::move(b)); + VERIFY( b.use_count() == 0 ); + VERIFY( a.use_count() == 1 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + a = std::move(std::shared_ptr<A>()); + VERIFY( D::delete_count == 1 ); + VERIFY( B::dtor_count == 1 ); + + return 0; +} + +int +test05() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a(std::move(std::shared_ptr<A>(new A))); + VERIFY( a.use_count() == 1 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/nullptr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/nullptr.cc new file mode 100644 index 000000000..82acaed36 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/nullptr.cc @@ -0,0 +1,93 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.11.2 Class template shared_ptr [util.smartptr.shared] + +#include <memory> +#include <cstddef> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// 20.9.11.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from nullptr + +struct deleter +{ + int count; + deleter() : count(0) { } + void operator()(std::nullptr_t) { ++count; } + void operator()(int*) const { throw "wrong type passed to deleter"; } +}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<int> p = nullptr; + VERIFY( p.get() == nullptr ); + VERIFY( p.use_count() == 0 ); + +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + deleter d; + std::shared_ptr<int> p(nullptr, std::ref(d)); + VERIFY( p.get() == nullptr ); + VERIFY( p.use_count() == 1 ); + + p = nullptr; + VERIFY( p.use_count() == 0 ); + VERIFY( d.count == 1 ); +} + + +void +test03() +{ + bool test __attribute__((unused)) = true; + + deleter d; + __gnu_test::tracker_allocator<int> a; + std::shared_ptr<int> p(nullptr, std::ref(d), a); + VERIFY( p.get() == nullptr ); + VERIFY( p.use_count() == 1 ); + + p = nullptr; + VERIFY( p.use_count() == 0 ); + VERIFY( d.count == 1 ); + + typedef __gnu_test::tracker_allocator_counter c; + VERIFY( c::get_destruct_count() == c::get_construct_count() ); + VERIFY( c::get_deallocation_count() == c::get_allocation_count() ); +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/pointer.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/pointer.cc new file mode 100644 index 000000000..701f12439 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/pointer.cc @@ -0,0 +1,80 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; +struct B : A { }; + + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from pointer + +int +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a = 0; + std::shared_ptr<A> p(a); + VERIFY( p.get() == 0 ); + VERIFY( p.use_count() == 1 ); + + return 0; +} + +int +test02() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A; + std::shared_ptr<A> p(a); + VERIFY( p.get() == a ); + VERIFY( p.use_count() == 1 ); + + return 0; +} + + +int +test03() +{ + bool test __attribute__((unused)) = true; + + B * const b = new B; + std::shared_ptr<A> p(b); + VERIFY( p.get() == b ); + VERIFY( p.use_count() == 1 ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr.cc new file mode 100644 index 000000000..cfca90d90 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.7.12.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.7.12.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from unique_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A> up(new A); + std::shared_ptr<A> sp(std::move(up)); + VERIFY( up.get() == 0 ); + VERIFY( sp.get() != 0 ); + VERIFY( sp.use_count() == 1 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc new file mode 100644 index 000000000..67485aee7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc @@ -0,0 +1,59 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.7.12.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +struct D { + void operator()(A* p) const { delete p; ++count; } + static int count; +}; + +int D::count = 0; + +// 20.7.12.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from unique_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A, D> up(new A, D()); + { + std::shared_ptr<A> sp(std::move(up)); + VERIFY( up.get() == 0 ); + VERIFY( sp.get() != 0 ); + VERIFY( sp.use_count() == 1 ); + } + VERIFY( D::count == 1 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_1.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_1.cc new file mode 100644 index 000000000..d0998c94c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_1.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.7.12.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +struct D { + typedef void result_type; + void operator()(A* p) { delete p; ++count; } + int count; +}; + + +// 20.7.12.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from unique_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + D d = D(); + std::unique_ptr<A, D&> up(new A, d); + { + std::shared_ptr<A> sp(std::move(up)); + VERIFY( up.get() == 0 ); + VERIFY( sp.get() != 0 ); + VERIFY( sp.use_count() == 1 ); + } + VERIFY( d.count == 1 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc new file mode 100644 index 000000000..7b09cfa7d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc @@ -0,0 +1,63 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.7.12.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <functional> +#include <testsuite_hooks.h> + +struct A { }; + +struct D { + typedef void result_type; + void operator()(A* p) { delete p; ++count; } + int count; +}; + + +// 20.7.12.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from unique_ptr +// See: http://gcc.gnu.org/ml/libstdc++/2008-09/msg00070.html. +int +test01() +{ + bool test __attribute__((unused)) = true; + + D d; + std::unique_ptr<A, D&> p1(new A, d); + + std::shared_ptr<A> p2(std::move(p1)); + + typedef std::reference_wrapper<D> D2; + D2* p3 = std::get_deleter<D2>(p2); + + VERIFY( p3 != 0 ); + VERIFY( &p3->get() == &d ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_neg.cc new file mode 100644 index 000000000..0e2fd68d5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_neg.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2008, 2009, 2010 Free Software Foundation +// +// 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.7.12.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.7.12.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from lvalue unique_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A> a; + std::shared_ptr<A> p(a); // { dg-error "cannot bind" } + + return 0; +} + +int +main() +{ + test01(); + return 0; +} +// { dg-excess-errors "initializing argument" } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr.cc new file mode 100644 index 000000000..7e24c1822 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from weak_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A; + std::shared_ptr<A> a1(a); + std::weak_ptr<A> wa(a1); + std::shared_ptr<A> a2(wa); + VERIFY( a2.get() == a ); + VERIFY( a2.use_count() == wa.use_count() ); + + return 0; +} + + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr_expired.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr_expired.cc new file mode 100644 index 000000000..cff9b3b99 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr_expired.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const] + +// Construction from expired weak_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a1(new A); + std::weak_ptr<A> wa(a1); + a1.reset(); + VERIFY( wa.expired() ); + try + { + std::shared_ptr<A> a2(wa); + } + catch (const std::bad_weak_ptr&) + { + // Expected. + __throw_exception_again; + } + catch (...) + { + // Failed. + } + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/36949.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/36949.cc new file mode 100644 index 000000000..31230776e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/36949.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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> + +struct A : std::enable_shared_from_this<A> { }; + +// libstdc++/36949 +void test01() +{ + std::make_shared<A>()->shared_from_this(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/alloc.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/alloc.cc new file mode 100644 index 000000000..e6bc6f47f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/alloc.cc @@ -0,0 +1,110 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using __gnu_test::tracker_allocator_counter; +using __gnu_test::tracker_allocator; + +struct A +{ + A(int i, double d, char c = '\0') : i(i), d(d), c(c) { ++ctor_count; } + explicit A(int i) : i(i), d(), c() { ++ctor_count; } + A() : i(), d(), c() { ++ctor_count; } + ~A() { ++dtor_count; } + int i; + double d; + char c; + static int ctor_count; + static int dtor_count; +}; +int A::ctor_count = 0; +int A::dtor_count = 0; + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + tracker_allocator_counter::reset(); + } +}; + +// 20.6.6.2.6 shared_ptr creation [util.smartptr.shared.create] + +void +test01() +{ + bool test __attribute__((unused)) = true; + reset_count_struct __attribute__((unused)) reset; + + { + std::shared_ptr<A> p1 = std::allocate_shared<A>(tracker_allocator<A>()); + VERIFY( p1.get() != 0 ); + VERIFY( p1.use_count() == 1 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( tracker_allocator_counter::get_allocation_count() > 0 ); + } + VERIFY( A::ctor_count == A::dtor_count ); + VERIFY( tracker_allocator_counter::get_allocation_count() + == tracker_allocator_counter::get_deallocation_count() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + reset_count_struct __attribute__((unused)) reset; + + std::shared_ptr<A> p1; + + p1 = std::allocate_shared<A>(tracker_allocator<A>(), 1); + VERIFY( A::ctor_count == 1 ); + VERIFY( tracker_allocator_counter::get_allocation_count() > 0 ); + + p1 = std::allocate_shared<A>(tracker_allocator<A>(), 1, 2.0); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 1 ); + VERIFY( tracker_allocator_counter::get_deallocation_count() > 0 ); + + p1 = std::allocate_shared<A>(tracker_allocator<A>(), 1, 2.0, '3'); + VERIFY( A::ctor_count == 3 ); + VERIFY( A::dtor_count == 2 ); + VERIFY( p1->i == 1 ); + VERIFY( p1->d == 2.0 ); + VERIFY( p1->c == '3' ); + + p1 = std::shared_ptr<A>(); + VERIFY( A::ctor_count == A::dtor_count ); + VERIFY( tracker_allocator_counter::get_allocation_count() + == tracker_allocator_counter::get_deallocation_count() ); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/dr402.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/dr402.cc new file mode 100644 index 000000000..462c6f848 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/dr402.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <new> +#include <testsuite_hooks.h> + +struct A +{ + void* operator new(size_t n) { return new char[sizeof(A)]; } + void operator delete(void* p, size_t) { delete (char*)p; } +}; + +// 20.6.6.2.6 shared_ptr creation [util.smartptr.shared.create] + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> p = std::make_shared<A>(); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/dr925.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/dr925.cc new file mode 100644 index 000000000..db176650e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/dr925.cc @@ -0,0 +1,90 @@ +// { dg-options "-std=gnu++0x -Wno-deprecated" } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.11.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ +}; + +std::unique_ptr<A> +create_unique_ptr() +{ + return std::unique_ptr<A>(new A()); +} + +std::auto_ptr<A> +create_auto_ptr() +{ + return std::auto_ptr<A>(new A()); +} + +void +process(std::shared_ptr<A> a) +{ + bool test __attribute__((unused)) = true; + + VERIFY( a.get() != 0 ); + VERIFY( a.use_count() == 1 ); +} + +// 20.9.11.2.1 shared_ptr creation [util.smartptr.shared.const] + +// Implicit conversion of auto_ptr to shared_ptr is allowed + +void +test01() +{ + process(create_auto_ptr()); +} + +void +test02() +{ + std::auto_ptr<A> a = create_auto_ptr(); + process(std::move(a)); +} + +// Implicit conversion of unique_ptr to shared_ptr is allowed + +void +test03() +{ + process(create_unique_ptr()); +} + +void +test04() +{ + std::unique_ptr<A> a = create_unique_ptr(); + process(std::move(a)); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/make.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/make.cc new file mode 100644 index 000000000..2441b9302 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/make.cc @@ -0,0 +1,97 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A(int i, double d, char c = '\0') : i(i), d(d), c(c) { ++ctor_count; } + explicit A(int i) : i(i), d(), c() { ++ctor_count; } + A() : i(), d(), c() { ++ctor_count; } + ~A() { ++dtor_count; } + int i; + double d; + char c; + static int ctor_count; + static int dtor_count; +}; +int A::ctor_count = 0; +int A::dtor_count = 0; + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + } +}; + +// 20.6.6.2.6 shared_ptr creation [util.smartptr.shared.create] + +void +test01() +{ + bool test __attribute__((unused)) = true; + reset_count_struct __attribute__((unused)) reset; + + { + std::shared_ptr<A> p1 = std::make_shared<A>(); + VERIFY( p1.get() != 0 ); + VERIFY( p1.use_count() == 1 ); + VERIFY( A::ctor_count == 1 ); + } + VERIFY( A::ctor_count == A::dtor_count ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + reset_count_struct __attribute__((unused)) reset; + + std::shared_ptr<A> p1; + + p1 = std::make_shared<A>(1); + VERIFY( A::ctor_count == 1 ); + + p1 = std::make_shared<A>(1, 2.0); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 1 ); + + p1 = std::make_shared<A>(1, 2.0, '3'); + VERIFY( A::ctor_count == 3 ); + VERIFY( A::dtor_count == 2 ); + VERIFY( p1->i == 1 ); + VERIFY( p1->d == 2.0 ); + VERIFY( p1->c == '3' ); + + p1 = std::shared_ptr<A>(); + VERIFY( A::ctor_count == A::dtor_count ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/dest/dest.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/dest/dest.cc new file mode 100644 index 000000000..5e1a6135f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/dest/dest.cc @@ -0,0 +1,134 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + +struct D +{ + void operator()(const B* p) { delete p; ++delete_count; } + static long delete_count; +}; +long D::delete_count = 0; + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + D::delete_count = 0; + } +}; + + +// 20.6.6.2.2 shared_ptr destructor [util.smartptr.shared.dest] + +// empty shared_ptr +int +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + { + std::shared_ptr<A> a; + } + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + VERIFY( D::delete_count == 0 ); + + return 0; +} + +// shared ownership +int +test02() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a; + { + a = std::shared_ptr<A>(new B, D()); + } + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + VERIFY( D::delete_count == 0 ); + + return 0; +} + +// exclusive ownership +int +test03() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + { + std::shared_ptr<A> a1(new B); + std::shared_ptr<A> a2(new B, D()); + } + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 2 ); + VERIFY( B::ctor_count == 2 ); + VERIFY( B::dtor_count == 2 ); + VERIFY( D::delete_count == 1 ); + + return 0; +} + + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/hash/1.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/hash/1.cc new file mode 100644 index 000000000..93f4739d7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/hash/1.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-11 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> + +void test01() +{ + bool test __attribute__((unused)) = true; + + struct T { }; + + std::shared_ptr<T> s0(new T); + std::hash<std::shared_ptr<T>> hs0; + std::hash<T*> hp0; + + VERIFY( hs0(s0) == hp0(s0.get()) ); + + std::__shared_ptr<T> s1(new T); + std::hash<std::__shared_ptr<T>> hs1; + std::hash<T*> hp1; + + VERIFY( hs1(s1) == hp1(s1.get()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/misc/24595.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/24595.cc new file mode 100644 index 000000000..b44c9bdf8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/24595.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +using std::get_deleter; + +// libstdc++/24595 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<int> sp; + VERIFY( !get_deleter<void(*)(int*)>(sp) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/misc/42019.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/42019.cc new file mode 100644 index 000000000..bea1771d2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/42019.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++0x -fno-rtti" } +// Copyright (C) 2009 Free Software Foundation +// +// 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.8.15.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +// libstdc++/42019 + +class A {}; + +struct B { + explicit B(int i) : i(i) { } + int i; +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> spA = std::make_shared<A>(); + + VERIFY( spA.get() != 0 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<B> spB = std::make_shared<B>(99); + + VERIFY( spB->i == 99 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/misc/io.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/io.cc new file mode 100644 index 000000000..a84f4bebf --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/io.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <sstream> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.8 shared_ptr I/O [util.smartptr.shared.io] + +// operator<< +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> p(new A); + std::ostringstream buf; + buf << p; + const std::string s = buf.str(); + buf.str(""); + buf << p.get(); + VERIFY( s == buf.str() ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/misc/swap.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/swap.cc new file mode 100644 index 000000000..10ccf8cad --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/swap.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.9 shared_ptr specialized algorithms [util.smartptr.shared.spec] + +// std::swap +int +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a1 = new A; + A * const a2 = new A; + std::shared_ptr<A> p1(a1); + std::shared_ptr<A> p2(a2); + std::swap(p1, p2); + VERIFY( p1.get() == a2 ); + VERIFY( p2.get() == a1 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/24805.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/24805.cc new file mode 100644 index 000000000..8b64014c0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/24805.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> + +// 20.6.6.2.4 shared_ptr modifiers [util.smartptr.shared.mod] + +// swap + +// libstdc++/24805 +using std::swap; diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset.cc new file mode 100644 index 000000000..c3b6745b4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset.cc @@ -0,0 +1,89 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; +struct B : A { }; +struct D +{ + void operator()(B* p) { delete p; ++delete_count; } + static long delete_count; +}; +long D::delete_count = 0; + +// 20.6.6.2.4 shared_ptr modifiers [util.smartptr.shared.mod] + +// reset +int +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A; + std::shared_ptr<A> p1(a); + std::shared_ptr<A> p2(p1); + p1.reset(); + VERIFY( p1.get() == 0 ); + VERIFY( p2.get() == a ); + + return 0; +} + +int +test02() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A; + B * const b = new B; + std::shared_ptr<A> p1(a); + std::shared_ptr<A> p2(p1); + p1.reset(b); + VERIFY( p1.get() == b ); + VERIFY( p2.get() == a ); + + return 0; +} + +int +test03() +{ + bool test __attribute__((unused)) = true; + + { + std::shared_ptr<A> p1; + p1.reset(new B, D()); + } + VERIFY( D::delete_count == 1 ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset_alloc.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset_alloc.cc new file mode 100644 index 000000000..61ac3b98e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset_alloc.cc @@ -0,0 +1,63 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using __gnu_test::tracker_allocator_counter; +using __gnu_test::tracker_allocator; + +struct A { }; +struct B : A { }; +struct D +{ + void operator()(B* p) { delete p; ++delete_count; } + static long delete_count; +}; +long D::delete_count = 0; + +// 20.6.6.2.4 shared_ptr modifiers [util.smartptr.shared.mod] + +// Reset with allocator +int +test01() +{ + bool test __attribute__((unused)) = true; + tracker_allocator_counter::reset(); + + { + std::shared_ptr<A> p1; + p1.reset(new B, D(), tracker_allocator<B>()); + VERIFY( tracker_allocator_counter::get_allocation_count() > 0 ); + } + VERIFY( D::delete_count == 1 ); + VERIFY( tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count() ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset_neg.cc new file mode 100644 index 000000000..5f133f547 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset_neg.cc @@ -0,0 +1,47 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.4 shared_ptr modifiers [util.smartptr.shared.mod] + +// reset +int +test01() +{ + bool test __attribute__((unused)) = true; + + const std::shared_ptr<A> p1(new A); + p1.reset(); // { dg-error "discards qualifiers" } + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/swap.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/swap.cc new file mode 100644 index 000000000..aab41ddc8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/swap.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.4 shared_ptr modifiers [util.smartptr.shared.mod] + +// swap +int +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a1 = new A; + A * const a2 = new A; + std::shared_ptr<A> p1(a1); + std::shared_ptr<A> p2(a2); + p1.swap(p2); + VERIFY( p1.get() == a2 ); + VERIFY( p2.get() == a1 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/swap_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/swap_neg.cc new file mode 100644 index 000000000..db173630f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/swap_neg.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.4 shared_ptr modifiers [util.smartptr.shared.mod] + +// swap +int +test01() +{ + bool test __attribute__((unused)) = true; + + const std::shared_ptr<A> p1(new A); + std::shared_ptr<A> p2(new A); + p1.swap(p2); // { dg-error "discards qualifiers" } + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/observers/bool_conv.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/bool_conv.cc new file mode 100644 index 000000000..dc2d53386 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/bool_conv.cc @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs] + +// conversion to bool +void +test01() +{ + bool test __attribute__((unused)) = true; + + const std::shared_ptr<A> p1; + VERIFY( static_cast<bool>(p1) == false ); + const std::shared_ptr<A> p2(p1); + VERIFY( static_cast<bool>(p2) == false ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> p1(new A); + VERIFY( static_cast<bool>(p1) ); + std::shared_ptr<A> p2(p1); + VERIFY( static_cast<bool>(p2) ); + p1.reset(); + VERIFY( !static_cast<bool>(p1) ); + VERIFY( static_cast<bool>(p2) ); +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> p1(new A); + std::shared_ptr<A> p2(p1); + p2.reset(new A); + VERIFY( static_cast<bool>(p1) ); + VERIFY( static_cast<bool>(p2) ); +} + + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/observers/get.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/get.cc new file mode 100644 index 000000000..104c7219d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/get.cc @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() : i() {} + int i; +}; + +// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs] + +// get +void +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A; + const std::shared_ptr<A> p(a); + VERIFY( p.get() == a ); +} + +// operator* +void +test02() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A; + const std::shared_ptr<A> p(a); + VERIFY( &*p == a ); +} + +// operator-> +void +test03() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A; + const std::shared_ptr<A> p(a); + VERIFY( &p->i == &a->i ); +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc new file mode 100644 index 000000000..79ede6833 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/owner_before.cc @@ -0,0 +1,94 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.13.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + int i; + virtual ~A() { } +}; + +struct B : A +{ +}; + +// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs] + +void +test01() +{ + bool test __attribute__((unused)) = true; + + // test empty shared_ptrs compare equivalent + std::shared_ptr<A> p1; + std::shared_ptr<B> p2; + VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) ); +} + + +// Construction from pointer +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a0; + + std::shared_ptr<A> a1(new A); + VERIFY( a1.owner_before(a0) || a0.owner_before(a1) ); + VERIFY( !(a1.owner_before(a0) && a0.owner_before(a1)) ); + + std::shared_ptr<B> b1(new B); + VERIFY( a1.owner_before(b1) || b1.owner_before(a1) ); + VERIFY( !(a1.owner_before(b1) && b1.owner_before(a1)) ); + + std::shared_ptr<A> a2(a1); + VERIFY( !a1.owner_before(a2) && !a2.owner_before(a1) ); + a2 = b1; + VERIFY( !b1.owner_before(a2) && !a2.owner_before(b1) ); + + std::weak_ptr<A> w1(a1); + VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) ); + std::weak_ptr<A> w2(a2); + VERIFY( !b1.owner_before(w2) && !w2.owner_before(b1) ); +} + +// Aliasing +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> p1(new A()); + std::shared_ptr<int> p2(p1, &p1->i); + VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) ); +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/observers/unique.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/unique.cc new file mode 100644 index 000000000..fae5eba37 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/unique.cc @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs] + +// unique +void +test01() +{ + bool test __attribute__((unused)) = true; + + const std::shared_ptr<A> p1; + VERIFY( !p1.unique() ); + const std::shared_ptr<A> p2(p1); + VERIFY( !p1.unique() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> p1(new A); + VERIFY( p1.unique() ); + std::shared_ptr<A> p2(p1); + VERIFY( !p1.unique() ); + p1.reset(); + VERIFY( !p1.unique() ); + VERIFY( p2.unique() ); +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> p1(new A); + std::shared_ptr<A> p2(p1); + p2.reset(new A); + VERIFY( p1.unique() ); + VERIFY( p2.unique() ); +} + + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/observers/use_count.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/use_count.cc new file mode 100644 index 000000000..a7f34cfac --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/use_count.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; +struct B : A { }; + +// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs] + +// use_count +void +test01() +{ + bool test __attribute__((unused)) = true; + + const std::shared_ptr<A> p1; + VERIFY( p1.use_count() == 0 ); + const std::shared_ptr<A> p2(p1); + VERIFY( p1.use_count() == 0 ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> p1(new A); + std::shared_ptr<A> p2(p1); + p1.reset(); + VERIFY( p1.use_count() == 0 ); + VERIFY( p2.use_count() == 1 ); +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> p1(new A); + std::shared_ptr<A> p2(p1); + p2.reset(new B); + VERIFY( p1.use_count() == 1 ); + VERIFY( p2.use_count() == 1 ); +} + + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..0f2d2c366 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/explicit_instantiation/1.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_tr1.h> + +using namespace __gnu_test; +using std::shared_ptr; +template class shared_ptr<int>; +template class shared_ptr<void>; +template class shared_ptr<ClassType>; +template class shared_ptr<IncompleteClass>; diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..781657cb0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/explicit_instantiation/2.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_tr1.h> + +// Check the _S_single lock policy can be instantiated. For a thread-enabled +// library this checks the templates can be instantiated for non-default +// lock policy, for a single-threaded lib this is redundant but harmless. +using namespace __gnu_test; +using std::__shared_ptr; +using std::_S_single; +template class __shared_ptr<int, _S_single>; +template class __shared_ptr<ClassType, _S_single>; +template class __shared_ptr<IncompleteClass, _S_single>; diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc new file mode 100644 index 000000000..b215f654a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc @@ -0,0 +1,197 @@ +// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthread -std=gnu++0x" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthreads -std=gnu++0x" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } + +#include <memory> +#include <random> +#include <vector> +#include <testsuite_hooks.h> +#include <iostream> +#include <cstdlib> + +#include <pthread.h> + +#ifdef _GLIBCXX_HAVE_UNISTD_H +#include <unistd.h> // To test for _POSIX_THREAD_PRIORITY_SCHEDULING +#endif + +/* This (brute-force) tests the atomicity and thus thread safety of the + * shared_ptr <- weak_ptr + * assignment operation by allocating a test object, retrieving a weak + * reference to it, and letting a number of threads repeatedly create strong + * references from the weak reference. + * Specifically, this tests the function _Sp_counted_base<true>::add_ref_lock() + */ + + +const unsigned int HAMMER_MAX_THREADS = 10; +const unsigned int POOL_SIZE = 1000; +const unsigned long HAMMER_REPEAT = 100000; +const unsigned long KILL_ONE_IN = 1000; + +struct A + { + static _Atomic_word counter; + A() + { + __gnu_cxx::__atomic_add(&counter, 1); + } + ~A() + { + __gnu_cxx::__atomic_add(&counter, -1); + } + }; + +_Atomic_word A::counter = 0; + +typedef std::shared_ptr<A> sp_A_t; +typedef std::weak_ptr<A> wp_A_t; + +typedef std::vector<sp_A_t> sp_vector_t; +typedef std::vector<wp_A_t> wp_vector_t; + +struct shared_and_weak_pools +{ + sp_vector_t& shared_pool; + wp_vector_t& weak_pool; + + shared_and_weak_pools(sp_vector_t& _shared_pool, wp_vector_t& _weak_pool) + : shared_pool(_shared_pool), weak_pool(_weak_pool) + { } +}; + +void* thread_hammer_and_kill(void* opaque_pools) +{ + shared_and_weak_pools& pools = *static_cast<shared_and_weak_pools*>(opaque_pools); + // Using the same parameters as in the RNG test cases. + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> rng; + + sp_vector_t::iterator cur_shared = pools.shared_pool.begin(); + wp_vector_t::iterator cur_weak = pools.weak_pool.begin(); + + for (unsigned int i = 0; i < HAMMER_REPEAT; ++i) + { + try + { + sp_A_t strong(*cur_weak); + } + catch (std::bad_weak_ptr& exception) + { + ++cur_weak; + if (cur_weak == pools.weak_pool.end()) + break; + } + + if (rng() % KILL_ONE_IN == 0) + { + cur_shared->reset(); + ++cur_shared; + } + } + return 0; +} + +void* thread_hammer(void* opaque_weak) +{ + wp_vector_t& weak_pool = *static_cast<wp_vector_t*>(opaque_weak); + // Using the same parameters as in the RNG test cases. + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> rng; + + wp_vector_t::iterator cur_weak = weak_pool.begin(); + + for (unsigned int i = 0; i < HAMMER_REPEAT; ++i) + { + try + { + sp_A_t strong(*cur_weak); + } + catch (std::bad_weak_ptr& exception) + { + ++cur_weak; + if (cur_weak == weak_pool.end()) + break; + } + } + return 0; +} + +int +test01() +{ + bool test __attribute__((unused)) = true; + sp_vector_t obj_pool(POOL_SIZE); + + for(sp_vector_t::iterator cur = obj_pool.begin(); cur != obj_pool.end(); ++cur) + { + cur->reset(new A); + } + // Obtain weak references. + std::vector<wp_vector_t> weak_pool(HAMMER_MAX_THREADS, wp_vector_t(obj_pool.begin(), obj_pool.end())); + + // Launch threads with pointer to weak reference. + pthread_t threads[HAMMER_MAX_THREADS]; +#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500 + pthread_setconcurrency (HAMMER_MAX_THREADS); +#endif + + pthread_attr_t tattr; + pthread_attr_init(&tattr); + + shared_and_weak_pools pools(obj_pool, weak_pool[0]); + pthread_create(threads, &tattr, thread_hammer_and_kill, static_cast<void*>(&pools)); + for (unsigned int worker = 1; worker < HAMMER_MAX_THREADS; worker++) + { + if (pthread_create(&threads[worker], &tattr, + thread_hammer, static_cast<void*>(&weak_pool[worker]))) + std::abort(); + } + // Wait for threads to complete, then check integrity of reference. + void* status; + for (unsigned int worker = 0; worker < HAMMER_MAX_THREADS; worker++) + { + if (pthread_join(threads[worker], &status)) + std::abort(); + } + obj_pool.clear(); + + VERIFY( A::counter == 0 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc new file mode 100644 index 000000000..c1ca796bb --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc @@ -0,0 +1,199 @@ +// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } + +#include <memory> +#include <random> +#include <vector> +#include <testsuite_hooks.h> +#include <iostream> +#include <cstdlib> + +#include <pthread.h> + +#ifdef _GLIBCXX_HAVE_UNISTD_H +#include <unistd.h> // To test for _POSIX_THREAD_PRIORITY_SCHEDULING +#endif + +/* This (brute-force) tests the atomicity and thus thread safety of the + * shared_ptr <- weak_ptr + * assignment operation by allocating a test object, retrieving a weak + * reference to it, and letting a number of threads repeatedly create strong + * references from the weak reference. + * Specifically, this tests the function _Sp_counted_base<true>::add_ref_lock() + */ + + +const unsigned int HAMMER_MAX_THREADS = 10; +const unsigned int POOL_SIZE = 1000; +const unsigned long HAMMER_REPEAT = 100000; +const unsigned long KILL_ONE_IN = 1000; + +struct A + { + static _Atomic_word counter; + A() + { + __gnu_cxx::__atomic_add(&counter, 1); + } + ~A() + { + __gnu_cxx::__atomic_add(&counter, -1); + } + }; + +_Atomic_word A::counter = 0; + +using std::_S_mutex; + +typedef std::__shared_ptr<A, _S_mutex> sp_A_t; +typedef std::__weak_ptr<A, _S_mutex> wp_A_t; + +typedef std::vector<sp_A_t> sp_vector_t; +typedef std::vector<wp_A_t> wp_vector_t; + +struct shared_and_weak_pools +{ + sp_vector_t& shared_pool; + wp_vector_t& weak_pool; + + shared_and_weak_pools(sp_vector_t& _shared_pool, wp_vector_t& _weak_pool) + : shared_pool(_shared_pool), weak_pool(_weak_pool) + { } +}; + +void* thread_hammer_and_kill(void* opaque_pools) +{ + shared_and_weak_pools& pools = *static_cast<shared_and_weak_pools*>(opaque_pools); + // Using the same parameters as in the RNG test cases. + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> rng; + + sp_vector_t::iterator cur_shared = pools.shared_pool.begin(); + wp_vector_t::iterator cur_weak = pools.weak_pool.begin(); + + for (unsigned int i = 0; i < HAMMER_REPEAT; ++i) + { + try + { + sp_A_t strong(*cur_weak); + } + catch (std::bad_weak_ptr& exception) + { + ++cur_weak; + if (cur_weak == pools.weak_pool.end()) + break; + } + + if (rng() % KILL_ONE_IN == 0) + { + cur_shared->reset(); + ++cur_shared; + } + } + return 0; +} + +void* thread_hammer(void* opaque_weak) +{ + wp_vector_t& weak_pool = *static_cast<wp_vector_t*>(opaque_weak); + // Using the same parameters as in the RNG test cases. + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> rng; + + wp_vector_t::iterator cur_weak = weak_pool.begin(); + + for (unsigned int i = 0; i < HAMMER_REPEAT; ++i) + { + try + { + sp_A_t strong(*cur_weak); + } + catch (std::bad_weak_ptr& exception) + { + ++cur_weak; + if (cur_weak == weak_pool.end()) + break; + } + } + return 0; +} + +int +test01() +{ + bool test __attribute__((unused)) = true; + sp_vector_t obj_pool(POOL_SIZE); + + for(sp_vector_t::iterator cur = obj_pool.begin(); cur != obj_pool.end(); ++cur) + { + cur->reset(new A); + } + // Obtain weak references. + std::vector<wp_vector_t> weak_pool(HAMMER_MAX_THREADS, wp_vector_t(obj_pool.begin(), obj_pool.end())); + + // Launch threads with pointer to weak reference. + pthread_t threads[HAMMER_MAX_THREADS]; +#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500 + pthread_setconcurrency (HAMMER_MAX_THREADS); +#endif + + pthread_attr_t tattr; + pthread_attr_init(&tattr); + + shared_and_weak_pools pools(obj_pool, weak_pool[0]); + pthread_create(threads, &tattr, thread_hammer_and_kill, static_cast<void*>(&pools)); + for (unsigned int worker = 1; worker < HAMMER_MAX_THREADS; worker++) + { + if (pthread_create(&threads[worker], &tattr, + thread_hammer, static_cast<void*>(&weak_pool[worker]))) + std::abort(); + } + // Wait for threads to complete, then check integrity of reference. + void* status; + for (unsigned int worker = 0; worker < HAMMER_MAX_THREADS; worker++) + { + if (pthread_join(threads[worker], &status)) + std::abort(); + } + obj_pool.clear(); + + VERIFY( A::counter == 0 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/move_iterators/1.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/move_iterators/1.cc new file mode 100644 index 000000000..788f7b172 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/move_iterators/1.cc @@ -0,0 +1,65 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + +#undef _GLIBCXX_CONCEPT_CHECKS + +#include <algorithm> +#include <iterator> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> +#include <testsuite_rvalref.h> + +using __gnu_test::test_container; +using __gnu_test::input_iterator_wrapper; +using __gnu_test::forward_iterator_wrapper; +using __gnu_test::rvalstruct; +using std::uninitialized_copy; + +typedef test_container<rvalstruct, input_iterator_wrapper> container_in; +typedef test_container<rvalstruct, forward_iterator_wrapper> container_out; + +void test01() +{ + bool test __attribute__((unused)) = true; + + int inarray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const int size = sizeof(inarray) / sizeof(int); + + rvalstruct in[size], out[size]; + std::copy(inarray, inarray + size, in); + + container_in incon(in, in + size); + container_out outcon(out, out + size); + + uninitialized_copy(std::move_iterator<input_iterator_wrapper<rvalstruct> >(incon.begin()), + std::move_iterator<input_iterator_wrapper<rvalstruct> >(incon.end()), + outcon.begin()); + VERIFY( std::equal(out, out + size, inarray) ); + for (int z = 0; z < size; ++z) + VERIFY( out[z].valid ); + for (int z = 0; z < size; ++z) + VERIFY( !in[z].valid ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy_n/move_iterators/1.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy_n/move_iterators/1.cc new file mode 100644 index 000000000..1a29613f4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy_n/move_iterators/1.cc @@ -0,0 +1,66 @@ +// { dg-options "-std=gnu++0x" } + +// 2008-06-29 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008, 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/>. + +#undef _GLIBCXX_CONCEPT_CHECKS + +#include <algorithm> +#include <iterator> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> +#include <testsuite_rvalref.h> + +using __gnu_test::test_container; +using __gnu_test::input_iterator_wrapper; +using __gnu_test::forward_iterator_wrapper; +using __gnu_test::rvalstruct; +using std::uninitialized_copy_n; + +typedef test_container<rvalstruct, input_iterator_wrapper> container_in; +typedef test_container<rvalstruct, forward_iterator_wrapper> container_out; + +void test01() +{ + bool test __attribute__((unused)) = true; + + int inarray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const int size = sizeof(inarray) / sizeof(int); + + rvalstruct in[size], out[size]; + std::copy(inarray, inarray + size, in); + + container_in incon(in, in + size); + container_out outcon(out, out + size); + + uninitialized_copy_n(std::move_iterator<input_iterator_wrapper<rvalstruct> >(incon.begin()), + size, outcon.begin()); + VERIFY( std::equal(out, out + size, inarray) ); + for (int z = 0; z < size; ++z) + VERIFY( out[z].valid ); + for (int z = 0; z < size; ++z) + VERIFY( !in[z].valid ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill/32158.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill/32158.cc new file mode 100644 index 000000000..961be2fdb --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill/32158.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2007, 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/>. + +// 20.4.4 specialized algorithms + +// { dg-do compile } + +#include <memory> +#include <utility> + +// c++/32158 + +typedef std::pair<const int, int> MyPair; + +void +Alpha(MyPair* start, MyPair* end) +{ + MyPair my_pair(1, 2); + std::uninitialized_fill(start, end, my_pair); +}; diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill_n/16505.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill_n/16505.cc new file mode 100644 index 000000000..380c53d39 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill_n/16505.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2004, 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/>. + +// 20.4.4 specialized algorithms + +// { dg-do compile } + +#include <memory> + +// libstdc++/16505 + +struct S { }; + +template + void + std::uninitialized_fill_n<S*, int, S>(S*, int, const S&); diff --git a/libstdc++-v3/testsuite/20_util/system_clock/1.cc b/libstdc++-v3/testsuite/20_util/system_clock/1.cc new file mode 100644 index 000000000..ead20873c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/system_clock/1.cc @@ -0,0 +1,39 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009, 2010 Free Software Foundation +// +// 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.8.5 Clocks [time.clock] + +#include <chrono> + +// 20.8.5.1 system_clock [time.clock.system] +int +main() +{ + using namespace std::chrono; + + system_clock::time_point t1 = system_clock::now(); + bool is_monotonic = system_clock::is_monotonic; + is_monotonic = is_monotonic; // suppress unused warning + std::time_t t2 = system_clock::to_time_t(t1); + system_clock::time_point t3 = system_clock::from_time_t(t2); + t3 = t3; // suppress unused warning + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/system_clock/constexpr_data.cc b/libstdc++-v3/testsuite/20_util/system_clock/constexpr_data.cc new file mode 100644 index 000000000..2407ef16a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/system_clock/constexpr_data.cc @@ -0,0 +1,52 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +namespace __gnu_test +{ + struct constexpr_member_data + { + template<typename _Ttesttype> + void + operator()() + { + struct _Concept + { + void __constraint() + { + constexpr auto v1 __attribute__((unused)) + = _Ttesttype::is_monotonic; + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + __gnu_test::constexpr_member_data test; + test.operator()<std::chrono::system_clock>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/temporary_buffer.cc b/libstdc++-v3/testsuite/20_util/temporary_buffer.cc new file mode 100644 index 000000000..b6e3d448a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/temporary_buffer.cc @@ -0,0 +1,50 @@ +// 2002-01-24 Phil Edwards <pme@gcc.gnu.org> + +// Copyright (C) 2002, 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/>. + +// 20.4.3 temporary buffers + +#include <memory> +#include <testsuite_hooks.h> + +struct junk { char j[12]; }; + +int main(void) +{ + bool test __attribute__((unused)) = true; + + typedef std::pair<junk*, std::ptrdiff_t> pair_type; + pair_type results = std::get_temporary_buffer<junk>(5); + + if (results.second != 0) + { + // make sure it works: test the returned capacity, and then construct + // some junk in the buffer. + // XXX + VERIFY( results.first != 0 ); + } + else + { + // if it says it didn't work, make sure it didn't work + VERIFY( results.first == 0 ); + } + + std::return_temporary_buffer(results.first); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/1.cc b/libstdc++-v3/testsuite/20_util/time_point/1.cc new file mode 100644 index 000000000..e18c6e58c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/1.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.4 Class template time_point [time.point] + +#include <chrono> +#include <testsuite_hooks.h> + +// 20.8.4.1 time_point constructors [time.point.cons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + time_point<system_clock> t1; + VERIFY(t1.time_since_epoch() == system_clock::duration::zero()); + + time_point<monotonic_clock> t2; + VERIFY(t2.time_since_epoch() == monotonic_clock::duration::zero()); + + time_point<high_resolution_clock> t3; + VERIFY(t3.time_since_epoch() == high_resolution_clock::duration::zero()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/2.cc b/libstdc++-v3/testsuite/20_util/time_point/2.cc new file mode 100644 index 000000000..8aab7ac69 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/2.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.4 Class template time_point [time.point] + +#include <chrono> +#include <testsuite_hooks.h> + +// 20.8.4.3 time_point arithmetic [time.point.arithmetic] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + time_point<system_clock> t1, t2; + t1 += seconds(1); + VERIFY(t2.time_since_epoch() + seconds(1) == t1.time_since_epoch()); + + t1 -= std::chrono::seconds(1); + VERIFY(t2.time_since_epoch() == t1.time_since_epoch()); +} + +// 20.8.4.5 time_point non-member arithmetic [time.point.nonmember] +void +test02() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + time_point<system_clock> t1; + time_point<system_clock> t2(t1 + seconds(1)); + VERIFY(t2.time_since_epoch() == t1.time_since_epoch() + seconds(1)); + + time_point<system_clock> t3(seconds(1) + t1); + VERIFY(t3.time_since_epoch() == t1.time_since_epoch() + seconds(1)); + + time_point<system_clock> t4(seconds(1)); + time_point<system_clock> t5(seconds(2)); + + time_point<system_clock> t6(t5 - seconds(1)); + VERIFY(t6.time_since_epoch() == t4.time_since_epoch()); + + time_point<system_clock> t7(t5 - t4); + VERIFY(t7.time_since_epoch() == t4.time_since_epoch()); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/3.cc b/libstdc++-v3/testsuite/20_util/time_point/3.cc new file mode 100644 index 000000000..ebf75b12f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/3.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.4 Class template time_point [time.point] + +#include <chrono> +#include <testsuite_hooks.h> + +// 20.8.4.6 time_point comparisons [time.point.comparisons] +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::chrono; + + time_point<system_clock> t1(seconds(1)); + time_point<system_clock> t2(seconds(1)); + time_point<system_clock> t3(seconds(2)); + + VERIFY(t1 == t2); + VERIFY(t1 != t3); + VERIFY(t1 < t3); + VERIFY(t1 <= t3); + VERIFY(t1 <= t2); + VERIFY(t3 > t1); + VERIFY(t3 >= t1); + VERIFY(t2 >= t1); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/comparison_operators/constexpr.cc b/libstdc++-v3/testsuite/20_util/time_point/comparison_operators/constexpr.cc new file mode 100644 index 000000000..427c51370 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/comparison_operators/constexpr.cc @@ -0,0 +1,30 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +int main() +{ + using namespace std::chrono; + __gnu_test::constexpr_comparison_operators test; + test.operator()<time_point<system_clock>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/time_point/cons/constexpr.cc new file mode 100644 index 000000000..d12d2f164 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/cons/constexpr.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +int main() +{ + using namespace std::chrono; + + __gnu_test::constexpr_default_constructible test1; + test1.operator()<time_point<system_clock>>(); + + __gnu_test::constexpr_single_value_constructible test2; + test2.operator()<time_point<system_clock>, seconds>(); + test2.operator()<time_point<system_clock, seconds>, + time_point<system_clock, minutes>>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/requirements/constexpr_functions.cc b/libstdc++-v3/testsuite/20_util/time_point/requirements/constexpr_functions.cc new file mode 100644 index 000000000..2beccd4ff --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/requirements/constexpr_functions.cc @@ -0,0 +1,59 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +namespace __gnu_test +{ + struct constexpr_member_functions + { + template<typename _Ttesttype> + void + operator()() + { + struct _Concept + { + void __constraint() + { + constexpr auto v1 __attribute__((unused)) + = _Ttesttype::min(); + constexpr auto v2 __attribute__((unused)) + = _Ttesttype::max(); + + constexpr _Ttesttype obj; + constexpr auto v3 __attribute__((unused)) + = obj.time_since_epoch(); + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + using namespace std::chrono; + __gnu_test::constexpr_member_functions test; + test.operator()<time_point<system_clock>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/time_point/requirements/explicit_instantiation/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/time_point/requirements/explicit_instantiation/explicit_instantiation.cc new file mode 100644 index 000000000..5c0455d65 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/requirements/explicit_instantiation/explicit_instantiation.cc @@ -0,0 +1,24 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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 <chrono> + +template class std::chrono::time_point<std::chrono::system_clock>; diff --git a/libstdc++-v3/testsuite/20_util/time_point_cast/constexpr.cc b/libstdc++-v3/testsuite/20_util/time_point_cast/constexpr.cc new file mode 100644 index 000000000..436a4fbfc --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point_cast/constexpr.cc @@ -0,0 +1,39 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <chrono> +#include <testsuite_common_types.h> + +int main() +{ + using namespace std::chrono; + typedef time_point<system_clock, hours> to_type; + typedef time_point<system_clock, minutes> from_type; + + // constexpr + constexpr minutes m(6000); + constexpr hours h(19); + constexpr to_type tpm(h); // time_point object with minutes + constexpr from_type tph(m); // time_point object with hours + + constexpr auto res(time_point_cast<hours>(tpm)); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/48476.cc new file mode 100644 index 000000000..efe0007a6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/48476.cc @@ -0,0 +1,51 @@ +// { 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/>. + +#include <tuple> +#include <type_traits> +#include <memory> +#include <testsuite_hooks.h> + +template<typename T> + typename std::decay<T>::type copy(T&& x) + { return std::forward<T>(x); } + +// libstdc++/48476 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<int> p(new int()), q, r; + + std::tuple<std::shared_ptr<int>&, int> t0(p, 23), t1(q, 0); + t1 = copy(t0); // shall be equivalent to + // q = p; std::get<1>(t1) = std::get<1>(t0); + VERIFY( q == p ); + + std::tuple<std::shared_ptr<int>&, char> t2(r, 0); + t2 = copy(t1); // shall be equivalent to + // r = q; std::get<1>(t2) = std::get<1>(t1); + VERIFY( r == q ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/35480_neg.cc b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/35480_neg.cc new file mode 100644 index 000000000..613c27f8b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/35480_neg.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2008, 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/>. + +// Tuple + +#include <tuple> + +// libstdc++/35480 +void test01() +{ + std::tuple<int> t1( 1 ); + std::tuple<int, int> t2( 1, 2 ); + if ( t1 < t2 ) {} // { dg-error "here" } + if ( t1 == t2 ) {} // { dg-error "here" } +} +// { dg-excess-errors "incomplete type" } diff --git a/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/comparisons.cc b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/comparisons.cc new file mode 100644 index 000000000..c10fb1cbc --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/comparisons.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + +// Tuple + +#include <tuple> +#include <testsuite_hooks.h> + +using namespace std; + +bool test __attribute__((unused)) = true; + +#define TEST1(x) VERIFY( x == x && !(x != x) && x <= x && !(x < x) ) + +int +main() +{ + int i=0; + int j=0; + int k=2; + tuple<int, int, int> a(0, 0, 0); + tuple<int, int, int> b(0, 0, 1); + tuple<int& , int& , int&> c(i,j,k); + tuple<const int&, const int&, const int&> d(c); + TEST1(a); + TEST1(b); + TEST1(c); + TEST1(d); + VERIFY(!(a > a) && !(b > b)); + VERIFY(a >= a && b >= b); + VERIFY(a < b && !(b < a) && a <= b && !(b <= a)); + VERIFY(b > a && !(a > b) && b >= a && !(a >= b)); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/41530.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/41530.cc new file mode 100644 index 000000000..6bd405c09 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/41530.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// Tuple + +#include <tuple> + +class A {}; +class B : public A {}; + +// PR libstdc++/41530 +void test01() +{ + std::tuple<B*> b; + std::tuple<A*> a1(b); + std::tuple<A*> a2(std::move(b)); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/44487.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/44487.cc new file mode 100644 index 000000000..dade58de8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/44487.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <tuple> + +int x, y; + +std::tuple<int&, int&> +foo1() +{ + std::pair<int&, int&> blah(x, y); + return blah; +} + +std::tuple<int&, int&> +foo2() +{ + const std::pair<int&, int&> blah(x, y); + return blah; +} + +std::tuple<int&, int&> +foo3() +{ + std::pair<int&, int&> blah(x, y); + return std::tuple<int&, int&>(std::move(blah)); +} + +std::tuple<int&, int&> +foo4() +{ + const std::pair<int&, int&> blah(x, y); + return std::tuple<int&, int&>(std::move(blah)); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/45228.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/45228.cc new file mode 100644 index 000000000..863d78847 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/45228.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <tuple> + +typedef std::tuple<int> Tuple_1; +typedef std::tuple<int, int> Tuple_2; +typedef std::tuple<int, int, int> Tuple_3; + + Tuple_1 A_1() { return Tuple_1(); } +const Tuple_1 B_1() { return Tuple_1(); } + + Tuple_2 A_2() { return Tuple_2(); } +const Tuple_2 B_2() { return Tuple_2(); } + + Tuple_3 A_3() { return Tuple_3(); } +const Tuple_3 B_3() { return Tuple_3(); } + +Tuple_1 test_A_1(A_1()); +Tuple_1 test_B_1(B_1()); + +Tuple_2 test_A_2(A_2()); +Tuple_2 test_B_2(B_2()); + +Tuple_3 test_A_3(A_3()); +Tuple_3 test_B_3(B_3()); diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc new file mode 100644 index 000000000..b5e3604d2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc @@ -0,0 +1,27 @@ +// { 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/>. + +#include <tuple> + +void f() +{ + int i = 0; + std::tuple<int&, int> t __attribute__((unused)) = std::forward_as_tuple(i, 0); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/assignment.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/assignment.cc new file mode 100644 index 000000000..111a398ff --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/assignment.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + +// Tuple + +#include <tuple> +#include <testsuite_hooks.h> + +using namespace std; + +int +main() +{ + bool test __attribute__((unused)) = true; + + tuple<> ta; + tuple<> tb; + ta = tb; + + tuple<int> tc(1); + tuple<int> td(0); + td = tc; + VERIFY(get<0>(td) == 1); + + int i=0; + tuple<int&> te(i); + te = tc; + VERIFY(i == 1); + + tuple<const int&> tf(tc); + + get<0>(tc) = 2; + VERIFY(get<0>(tf) == 2); + tuple<double> tg; + tg = tc; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/big_tuples.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/big_tuples.cc new file mode 100644 index 000000000..7bcb51771 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/big_tuples.cc @@ -0,0 +1,105 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2009, 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/>. + +// Tuple + +#include <tuple> +#include <utility> // for pair +#include <testsuite_hooks.h> + +using namespace std; + +// A simple class without conversions to check some things +struct foo +{ }; + +void +test_constructors() +{ + bool test __attribute__((unused)) = true; + + int x1=0,x2=0; + const int &z1=x1; + + // Test empty constructor + tuple<> ta __attribute__((unused)); + tuple<int,int> tb; + // Test construction from values + tuple<int,int> tc(x1,x2); + tuple<int,int&> td(x1,x2); + tuple<const int&> te(z1); + x1=1; + x2=1; + VERIFY(get<0>(td) == 0 && get<1>(td) == 1 && get<0>(te) == 1); + + // Test identical tuple copy constructor + tuple<int,int> tf(tc); + tuple<int,int> tg(td); + tuple<const int&> th(te); + // Test different tuple copy constructor + tuple<int,double> ti(tc); + tuple<int,double> tj(td); + // Test constructing from a pair + pair<int,int> pair1(1,1); + const pair<int,int> pair2(pair1); + tuple<int,int> tl(pair1); + tuple<int,const int&> tm(pair1); + tuple<int,int> tn(pair2); + tuple<int,const int&> to(pair2); +} + +int +main(void) +{ + //test construction + typedef tuple<int,int,int,int,int,int,int,int,int,int> type1; + type1 a(0, 0, 0, 0, 0, 0, 0, 0, 0, 1); + type1 b(0, 0, 0, 0, 0, 0, 0, 0, 0, 2); + type1 c(a); + typedef tuple<int,int,int,int,int,int,int,int,int,char> type2; + type2 d(0, 0, 0, 0, 0, 0, 0, 0, 0, 3); + type1 e(d); + typedef tuple<foo,int,int,int,int,int,int,int,int,foo> type3; + // get + VERIFY(get<9>(a)==1 && get<9>(b)==2); + // comparisons + VERIFY(a==a && !(a!=a) && a<=a && a>=a && !(a<a) && !(a>a)); + VERIFY(!(a==b) && a!=b && a<=b && a<b && !(a>=b) && !(a>b)); + //tie + { + int i = 0; + tie(ignore, ignore, ignore, ignore, ignore, ignore, ignore, ignore, + ignore, i) = a; + VERIFY(i == 1); + } + //test_assignment + a=d; + a=b; + //make_tuple + make_tuple(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + + //tuple_size + VERIFY(tuple_size<type3>::value == 10); + //tuple_element + { + foo q1; + tuple_element<0,type3>::type q2(q1); + tuple_element<9,type3>::type q3(q1); + } +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/constexpr.cc new file mode 100644 index 000000000..b5eba73fd --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/constexpr.cc @@ -0,0 +1,47 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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_common_types.h> + +int main() +{ + __gnu_test::constexpr_default_constructible test1; + test1.operator()<std::tuple<int, int>>(); + + __gnu_test::constexpr_single_value_constructible test2; + test2.operator()<std::tuple<int, int>, std::tuple<int, int>>(); + // test2.operator()<std::tuple<int, int>, std::pair<short, short>>(); + // test2.operator()<std::tuple<int>, std::tuple<short>>(); + // test2.operator()<std::tuple<int, int>, std::tuple<short, short>>(); + + // test 3 + const int i1(129); + const int i2(6); + constexpr std::tuple<int, int> p3(i1, i2); + + // test 4 + const int i3(415); + const int i4(550); + const int i5(6414); + constexpr std::tuple<int, int, int, int, int> p4(i1, i2, i3, i4, i5); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/constructor.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/constructor.cc new file mode 100644 index 000000000..9871f4959 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/constructor.cc @@ -0,0 +1,65 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2008, 2009, 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/>. + +// Tuple + +#include <tuple> +#include <utility> // for pair +#include <testsuite_hooks.h> + +using namespace std; + +int +main() +{ + bool test __attribute__((unused)) = true; + + int x1=0,x2=0; + const int &z1=x1; + + // Test empty constructor + tuple<> ta __attribute__((unused)); + tuple<int,int> tb; + // Test construction from values + tuple<int,int> tc(x1,x2); + tuple<int,int&> td(x1,x2); + tuple<const int&> te(z1); + x1=1; + x2=1; + VERIFY(get<0>(td) == 0 && get<1>(td) == 1 && get<0>(te) == 1); + + // Test identical tuple copy constructor + tuple<int,int> tf(tc); + tuple<int,int> tg(td); + tuple<const int&> th(te); + // Test different tuple copy constructor + tuple<int,double> ti(tc); + tuple<int,double> tj(td); + //tuple<int&, int&> tk(tc); + tuple<const int&, const int&> tl(tc); + tuple<const int&, const int&> tm(tl); + // Test constructing from a pair + pair<int,int> pair1(1,1); + const pair<int,int> pair2(pair1); + tuple<int,int> tn(pair1); + tuple<int,const int&> to(pair1); + tuple<int,int> tp(pair2); + tuple<int,const int&> tq(pair2); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/converting.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/converting.cc new file mode 100644 index 000000000..def1b521d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/converting.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <tuple> + +// http://gcc.gnu.org/ml/libstdc++/2008-02/msg00047.html +std::tuple<int> ts1; +std::tuple<unsigned> tu1(ts1); + +std::tuple<int, int> ts2; +std::tuple<unsigned, unsigned> tu2(ts2); + +std::tuple<int, int, int> ts3; +std::tuple<unsigned, unsigned, unsigned> tu3(ts3); + +std::tuple<int, unsigned> tm2; +std::tuple<unsigned, int> tm2_(tm2); + +std::tuple<int, unsigned, int> tm3; +std::tuple<unsigned, int, unsigned> tm3_(tm3); diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/23978.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/23978.cc new file mode 100644 index 000000000..7db57bc70 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/23978.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } +// +// Copyright (C) 2007, 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/>. + +// Tuple + +#include <tuple> +#include <utility> +#include <testsuite_hooks.h> + +using namespace std; + +// libstdc++/23978 +void test01() +{ + bool test __attribute__((unused)) = true; + + pair<int, int> p(1, 2); + int x = 0; + int y = 0; + tie(x, y) = p; + VERIFY( x == 1 && y == 2 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc new file mode 100644 index 000000000..1607e4552 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc @@ -0,0 +1,85 @@ +// { 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/>. + +#include <tuple> +#include <type_traits> +#include <testsuite_hooks.h> + +template<typename T> + typename std::decay<T>::type copy(T&& x) + { return std::forward<T>(x); } + +template<typename... Args1, typename... Args2> + void + check_tuple_cat(std::tuple<Args1...> t1, std::tuple<Args2...> t2) + { + bool test __attribute__((unused)) = true; + + typedef std::tuple<Args1..., Args2...> concatenated; + + auto cat1 = std::tuple_cat( t1, t2 ); + auto cat2 = std::tuple_cat(copy(t1), t2 ); + auto cat3 = std::tuple_cat( t1, copy(t2)); + auto cat4 = std::tuple_cat(copy(t1), copy(t2)); + + static_assert( std::is_same<decltype(cat1), concatenated>::value, "" ); + static_assert( std::is_same<decltype(cat2), concatenated>::value, "" ); + static_assert( std::is_same<decltype(cat3), concatenated>::value, "" ); + static_assert( std::is_same<decltype(cat4), concatenated>::value, "" ); + + VERIFY( cat1 == cat2 ); + VERIFY( cat1 == cat3 ); + VERIFY( cat1 == cat4 ); + } + +// libstdc++/48476 +void test01() +{ + int i = 0; + std::tuple<> t0; + std::tuple<int&> t1(i); + std::tuple<int&, int> t2(i, 0); + std::tuple<int const&, int, double> t3(i, 0, 0); + + check_tuple_cat(t0, t0); + check_tuple_cat(t0, t1); + check_tuple_cat(t0, t2); + check_tuple_cat(t0, t3); + + check_tuple_cat(t1, t0); + check_tuple_cat(t1, t1); + check_tuple_cat(t1, t2); + check_tuple_cat(t1, t3); + + check_tuple_cat(t2, t0); + check_tuple_cat(t2, t1); + check_tuple_cat(t2, t2); + check_tuple_cat(t2, t3); + + check_tuple_cat(t3, t0); + check_tuple_cat(t3, t1); + check_tuple_cat(t3, t2); + check_tuple_cat(t3, t3); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/forward_as_tuple.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/forward_as_tuple.cc new file mode 100644 index 000000000..bad4ad49c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/forward_as_tuple.cc @@ -0,0 +1,72 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-04-30 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/>. + +// Tuple + +#include <tuple> +#include <type_traits> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::forward_as_tuple(); + + VERIFY( std::get<0>(std::forward_as_tuple(-1)) == -1 ); + VERIFY( (std::is_same<decltype(std::forward_as_tuple(-1)), + std::tuple<int&&>>::value) ); + + const int i1 = 1; + const int i2 = 2; + const double d1 = 4.0; + auto t1 = std::forward_as_tuple(i1, i2, d1); + VERIFY( (std::is_same<decltype(t1), std::tuple<const int&, + const int&, const double&>>::value) ); + VERIFY( std::get<0>(t1) == i1 ); + VERIFY( std::get<1>(t1) == i2 ); + VERIFY( std::get<2>(t1) == d1 ); + + typedef const int a_type1[3]; + a_type1 a1 = { -1, 1, 2 }; + auto t2 = std::forward_as_tuple(a1); + VERIFY( (std::is_same<decltype(t2), std::tuple<a_type1&>>::value) ); + VERIFY( std::get<0>(t2)[0] == a1[0] ); + VERIFY( std::get<0>(t2)[1] == a1[1] ); + VERIFY( std::get<0>(t2)[2] == a1[2] ); + + typedef int a_type2[2]; + a_type2 a2 = { 2, -2 }; + volatile int i4 = 1; + auto t3 = std::forward_as_tuple(a2, i4); + VERIFY( (std::is_same<decltype(t3), std::tuple<a_type2&, + volatile int&>>::value) ); + VERIFY( std::get<0>(t3)[0] == a2[0] ); + VERIFY( std::get<0>(t3)[1] == a2[1] ); + VERIFY( std::get<1>(t3) == i4 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/make_tuple.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/make_tuple.cc new file mode 100644 index 000000000..7521111fa --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/make_tuple.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + +// Tuple + +#include <tuple> +#include <functional> +#include <testsuite_hooks.h> + +using namespace std; + +int +main() +{ + bool test __attribute__((unused)) = true; + + int i=0; + make_tuple(1,2,4.0); + make_tuple(ref(i)) = tuple<int>(1); + VERIFY(i == 1); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie.cc new file mode 100644 index 000000000..a76928979 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + +// Tuple + +#include <tuple> +#include <testsuite_hooks.h> + +using namespace std; + +int +main() +{ + bool test __attribute__((unused)) = true; + + int x1 = 0; + int x2 = 0; + int y1 = 0; + int y2 = 0; + tuple<int,int> ta(1,1); + tuple<const int&,const int&> tc(x1,x2); + tie(y1,y2)=ta; + VERIFY(y1 == 1 && y2 == 1); + tie(y1,y2)=tc; + VERIFY(y1 == 0 && y2 == 0); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie2.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie2.cc new file mode 100644 index 000000000..538c3e8e1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie2.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + +// Tuple + +#include <tuple> +#include <string> +#include <testsuite_hooks.h> + +int +main() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + int i; + string s; + + tie(i, ignore, s) = make_tuple(42, 3.14, "C++"); + VERIFY( i == 42 ); + VERIFY( s == "C++" ); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/element_access/get.cc b/libstdc++-v3/testsuite/20_util/tuple/element_access/get.cc new file mode 100644 index 000000000..1ec01cfca --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/element_access/get.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + +// Tuple + +#include <tuple> +#include <testsuite_hooks.h> + +using namespace std; + +int +main() +{ + bool test __attribute__((unused)) = true; + + int j=1; + const int k=2; + tuple<int,int &,const int&> a(0,j,k); + const tuple<int,int &,const int&> b(1,j,k); + VERIFY(get<0>(a)==0 && get<1>(a)==1 && get<2>(a)==2); + get<0>(a)=3; + get<1>(a)=4; + VERIFY(get<0>(a)==3 && get<1>(a)==4); + VERIFY(j==4); + get<1>(b)=5; + VERIFY(get<0>(b)==1 && get<1>(b)==5 && get<2>(b)==2); + VERIFY(j==5); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/moveable.cc b/libstdc++-v3/testsuite/20_util/tuple/moveable.cc new file mode 100644 index 000000000..0fedd83ed --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/moveable.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on tuple. If the implementation changed +// this test may begin to fail. + +#include <tuple> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::tuple<int, double> a(1, 2.0), b; + b = std::move(a); + VERIFY( std::get<0>(b) == 1 && std::get<1>(b) == 2.0 ); + VERIFY( std::get<0>(a) == 1 && std::get<1>(a) == 2.0 ); + + std::tuple<int, double> c(std::move(b)); + VERIFY( std::get<0>(c) == 1 && std::get<1>(c) == 2.0 ); + VERIFY( std::get<0>(b) == 1 && std::get<1>(b) == 2.0 ); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/moveable2.cc b/libstdc++-v3/testsuite/20_util/tuple/moveable2.cc new file mode 100644 index 000000000..f08007421 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/moveable2.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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 <tuple> +#include <utility> + +struct MoveOnly +{ + MoveOnly () { } + + MoveOnly (MoveOnly&&) { } + + MoveOnly& operator=(MoveOnly&&) + { return *this; } + +private: + MoveOnly(MoveOnly const&); // = delete + MoveOnly& operator=(MoveOnly const&); // = delete +}; + +MoveOnly +make_move_only () +{ return MoveOnly(); } + +// http://gcc.gnu.org/ml/libstdc++/2008-02/msg00046.html +void test01() +{ + typedef std::tuple<MoveOnly> move_only_tuple; + + move_only_tuple t1(make_move_only()); + move_only_tuple t2(std::move(t1)); + move_only_tuple t3 = std::move(t2); + t1 = std::move(t3); + + typedef std::tuple<MoveOnly, MoveOnly> move_only_tuple2; + + move_only_tuple2 t4(make_move_only(), make_move_only()); + move_only_tuple2 t5(std::move(t4)); + move_only_tuple2 t6 = std::move(t5); + t4 = std::move(t6); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/requirements/dr801.cc b/libstdc++-v3/testsuite/20_util/tuple/requirements/dr801.cc new file mode 100644 index 000000000..fd21b9ee5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/requirements/dr801.cc @@ -0,0 +1,52 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 <tuple> +#include <type_traits> + +// DR 801, pair and tuple vs. "passed in registers" +void test_trivial() +{ + // PODType, TType, NType, SLType, LType, NLType, LTypeDerived + typedef std::tuple<int, int> tuple_type; + // static_assert(std::is_literal_type<tuple_type>::value, "! literal"); + static_assert(std::has_trivial_copy_constructor<tuple_type>::value, + "! triv copy"); + static_assert(std::has_trivial_destructor<tuple_type>::value, + "! triv destructor"); + // static_assert(std::is_standard_layout<tuple_type>::value, + // "! standard layout"); + + // Negative + /* + static_assert(std::has_trivial_default_constructor<tuple_type>::value, + "! triv default"); + static_assert(std::has_trivial_copy_assign<tuple_type>::value, + "! triv assign"); + static_assert(std::is_trivial<tuple_type>::value, "! triv"); + static_assert(std::is_pod<tuple_type>::value, "! pod"); + */ +} + +int main() +{ + test_trivial(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/tuple/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..22b8f50f5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/requirements/explicit_instantiation.cc @@ -0,0 +1,24 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <tuple> + +template class std::tuple<short, int, double>; diff --git a/libstdc++-v3/testsuite/20_util/tuple/swap.cc b/libstdc++-v3/testsuite/20_util/tuple/swap.cc new file mode 100644 index 000000000..613e9c2ff --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/swap.cc @@ -0,0 +1,111 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on tuple. If the implementation changed +// this test may begin to fail. + +#include <tuple> +#include <utility> +#include <testsuite_hooks.h> + +struct MoveOnly +{ + explicit MoveOnly (int j) : i(j) { } + + MoveOnly (MoveOnly&& m) : i(m.i) { } + + MoveOnly& operator=(MoveOnly&& m) + { i = m.i; return *this; } + + MoveOnly(MoveOnly const&) = delete; + MoveOnly& operator=(MoveOnly const&) = delete; + + bool operator==(MoveOnly const& m) + { return i == m.i; } + + void swap(MoveOnly& m) + { std::swap(m.i, i); } + + int i; +}; + +void swap(MoveOnly& m1, MoveOnly& m2) +{ m1.swap(m2); } + +MoveOnly +make_move_only (int i) +{ return MoveOnly(i); } + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::tuple<> t1, t2; + std::swap(t1, t2); + + VERIFY( t1 == t2 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::tuple<int> t1(1), t2(2); + std::swap(t1, t2); + + VERIFY( std::get<0>(t1) == 2 && std::get<0>(t2) == 1 ); +} + +void test03() +{ + bool test __attribute__((unused)) = true; + + std::tuple<int, float> t1(1, 1.0f), t2(2, 2.0f); + std::swap(t1, t2); + + VERIFY( std::get<0>(t1) == 2 && std::get<0>(t2) == 1 ); + VERIFY( std::get<1>(t1) == 2.0f && std::get<1>(t2) == 1.0f ); +} + +void test04() +{ + bool test __attribute__((unused)) = true; + + std::tuple<int, float, MoveOnly> + t1(1, 1.0f, make_move_only(1)), + t2(2, 2.0f, make_move_only(2)); + + std::swap(t1, t2); + + VERIFY( std::get<0>(t1) == 2 && std::get<0>(t2) == 1 ); + VERIFY( std::get<1>(t1) == 2.0f && std::get<1>(t2) == 1.0f ); + VERIFY( std::get<2>(t1) == make_move_only(2) + && std::get<2>(t2) == make_move_only(1) ); +} + +int main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc b/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc new file mode 100644 index 000000000..9344ea082 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/tuple_element.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + +// Tuple + +#include <tuple> + +using namespace std; + +struct foo +{ }; + +int +main() +{ + // As foo isn't constructible from anything else, this + // lets us check if type is returning foo when it should + foo q1; + tuple_element<0,tuple<foo,void,int> >::type q2(q1); + tuple_element<2,tuple<void,int,foo> >::type q3(q1); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/tuple_size.cc b/libstdc++-v3/testsuite/20_util/tuple/tuple_size.cc new file mode 100644 index 000000000..51f4a2db8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/tuple_size.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + +// Tuple + +#include <tuple> +#include <testsuite_hooks.h> + +using namespace std; + +int +main() +{ + bool test __attribute__((unused)) = true; + + VERIFY(tuple_size<tuple<> >::value == 0); + VERIFY(tuple_size<tuple<int> >::value == 1); + VERIFY(tuple_size<tuple<void> >::value == 1); + typedef tuple<int,const int&,void> test_tuple1; + VERIFY(tuple_size<test_tuple1>::value == 3); + VERIFY(tuple_size<tuple<tuple<void> > >::value == 1); +} diff --git a/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators.cc b/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators.cc new file mode 100644 index 000000000..5ca53967d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators.cc @@ -0,0 +1,88 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-09-22 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 Free Software Foundation +// +// 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 <typeindex> +#include <testsuite_hooks.h> + +#define TEST3(TI1, TI2, TO1, TO2) \ + VERIFY( (TI1 == TI2) == (TO1 == TO2) ); \ + VERIFY( (TI1 != TI2) == (TO1 != TO2) ); \ + VERIFY( (TI1 < TI2) == (TO1.before(TO2)) ); \ + VERIFY( (TI1 <= TI2) == (!TO2.before(TO1)) ); \ + VERIFY( (TI1 > TI2) == (TO2.before(TO1)) ); \ + VERIFY( (TI1 >= TI2) == (!TO1.before(TO2)) ); + +#define TEST2(TI, TO) \ + TEST3(TI, ti1, TO, to1) \ + TEST3(TI, ti2, TO, to2) \ + TEST3(TI, ti3, TO, to3) \ + TEST3(TI, ti4, TO, to4) \ + TEST3(TI, ti5, TO, to5) \ + TEST3(TI, ti6, TO, to6) \ + TEST3(TI, ti7, TO, to7) + +#define TEST \ + TEST2(ti1, to1) \ + TEST2(ti2, to2) \ + TEST2(ti3, to3) \ + TEST2(ti4, to4) \ + TEST2(ti5, to5) \ + TEST2(ti6, to6) \ + TEST2(ti7, to7) + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + class Abraca { }; + Abraca a1, a2_; + const Abraca a2 = a2_; + + const type_info& to1 = typeid(int); + const type_index ti1(to1); + + const type_info& to2 = typeid(double); + const type_index ti2(to2); + + const type_info& to3 = typeid(Abraca); + const type_index ti3(to3); + + const type_info& to4 = typeid(const Abraca); + const type_index ti4(to4); + + const type_info& to5 = typeid(const Abraca&); + const type_index ti5(to5); + + const type_info& to6 = typeid(a1); + const type_index ti6(to6); + + const type_info& to7 = typeid(a2); + const type_index ti7(to7); + + TEST +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/typeindex/hash.cc b/libstdc++-v3/testsuite/20_util/typeindex/hash.cc new file mode 100644 index 000000000..2468ea693 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/typeindex/hash.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-09-22 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 Free Software Foundation +// +// 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 <typeindex> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + class Abraca { }; + Abraca a1, a2_; + const Abraca a2 = a2_; + + const type_index ti1(typeid(int)); + VERIFY( hash<type_index>()(ti1) == ti1.hash_code() ); + + const type_index ti2(typeid(double)); + VERIFY( hash<type_index>()(ti2) == ti2.hash_code() ); + + const type_index ti3(typeid(Abraca)); + VERIFY( hash<type_index>()(ti3) == ti3.hash_code() ); + + const type_index ti4(typeid(const Abraca)); + VERIFY( hash<type_index>()(ti4) == ti4.hash_code() ); + + const type_index ti5(typeid(const Abraca&)); + VERIFY( hash<type_index>()(ti5) == ti5.hash_code() ); + + const type_index ti6(typeid(a1)); + VERIFY( hash<type_index>()(ti6) == ti6.hash_code() ); + + const type_index ti7(typeid(a2)); + VERIFY( hash<type_index>()(ti7) == ti7.hash_code() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc b/libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc new file mode 100644 index 000000000..f12b6cbb9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-09-22 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 Free Software Foundation +// +// 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 <typeindex> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + class Abraca { }; + Abraca a1, a2_; + const Abraca a2 = a2_; + + const type_info& to1 = typeid(int); + const type_index ti1(to1); + VERIFY( ti1.hash_code() == to1.hash_code() ); + + const type_info& to2 = typeid(double); + const type_index ti2(to2); + VERIFY( ti2.hash_code() == to2.hash_code() ); + + const type_info& to3 = typeid(Abraca); + const type_index ti3(to3); + VERIFY( ti3.hash_code() == to3.hash_code() ); + + const type_info& to4 = typeid(const Abraca); + const type_index ti4(to4); + VERIFY( ti4.hash_code() == to4.hash_code() ); + + const type_info& to5 = typeid(const Abraca&); + const type_index ti5(to5); + VERIFY( ti5.hash_code() == to5.hash_code() ); + + const type_info& to6 = typeid(a1); + const type_index ti6(to6); + VERIFY( ti6.hash_code() == to6.hash_code() ); + + const type_info& to7 = typeid(a2); + const type_index ti7(to7); + VERIFY( ti7.hash_code() == to7.hash_code() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/typeindex/name.cc b/libstdc++-v3/testsuite/20_util/typeindex/name.cc new file mode 100644 index 000000000..fa6e6945c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/typeindex/name.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-09-22 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 Free Software Foundation +// +// 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 <typeindex> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + class Abraca { }; + Abraca a1, a2_; + const Abraca a2 = a2_; + + const type_info& to1 = typeid(int); + const type_index ti1(to1); + VERIFY( ti1.name() == to1.name() ); + + const type_info& to2 = typeid(double); + const type_index ti2(to2); + VERIFY( ti2.name() == to2.name() ); + + const type_info& to3 = typeid(Abraca); + const type_index ti3(to3); + VERIFY( ti3.name() == to3.name() ); + + const type_info& to4 = typeid(const Abraca); + const type_index ti4(to4); + VERIFY( ti4.name() == to4.name() ); + + const type_info& to5 = typeid(const Abraca&); + const type_index ti5(to5); + VERIFY( ti5.name() == to5.name() ); + + const type_info& to6 = typeid(a1); + const type_index ti6(to6); + VERIFY( ti6.name() == to6.name() ); + + const type_info& to7 = typeid(a2); + const type_index ti7(to7); + VERIFY( ti7.name() == to7.name() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635.cc new file mode 100644 index 000000000..99b412b58 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2011 Free Software Foundation +// +// 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> + +struct Deleter +{ + Deleter() = default; + Deleter(const Deleter&) = default; + Deleter(Deleter&&) = default; + + Deleter& + operator=(const Deleter&) + { + bool test __attribute__((unused)) = true; + VERIFY( true ); + return *this; + } + + Deleter& + operator=(Deleter&&) + { + bool test __attribute__((unused)) = true; + VERIFY( false ); + return *this; + } + + template<class T> + void + operator()(T*) const { } +}; + +struct DDeleter : Deleter { }; + +// libstdc++/48635 +void test01() +{ + Deleter d; + + std::unique_ptr<int, Deleter&> p1(nullptr, d), p2(nullptr, d); + p2 = std::move(p1); + + DDeleter dd; + + std::unique_ptr<int, DDeleter&> p1t(nullptr, dd); + std::unique_ptr<int, Deleter&> p2t(nullptr, d); + p2t = std::move(p1t); + + std::unique_ptr<int[], Deleter&> p1a(nullptr, d), p2a(nullptr, d); + p2a = std::move(p1a); + + std::unique_ptr<int[], DDeleter&> p1at(nullptr, dd); + std::unique_ptr<int[], Deleter&> p2at(nullptr, d); + p2at = std::move(p1at); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc new file mode 100644 index 000000000..1ed53ee2d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2011 Free Software Foundation +// +// 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> + +struct D; + +struct B +{ + B& operator=(D&) = delete; // { dg-error "declared here" } + + template<class T> + void operator()(T*) const {} +}; + +struct D : B { }; + +// libstdc++/48635 +void f() +{ + B b; + D d; + + std::unique_ptr<int, B&> ub(nullptr, b); + std::unique_ptr<int, D&> ud(nullptr, d); + ub = std::move(ud); +// { dg-error "use of deleted function" "" { target *-*-* } 189 } + + std::unique_ptr<int[], B&> uba(nullptr, b); + std::unique_ptr<int[], D&> uda(nullptr, d); + uba = std::move(uda); +// { dg-error "use of deleted function" "" { target *-*-* } 329 } +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc new file mode 100644 index 000000000..501bad385 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc @@ -0,0 +1,53 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009, 2010 Free Software Foundation +// +// 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> + +struct base { virtual ~base() {} }; +struct derived : base {}; + +void +test01() +{ + std::unique_ptr<derived> p1(new derived); + std::unique_ptr<derived> p2(new derived); +// p2 = p1; // should not compile + p2 = std::move(p1); + std::unique_ptr<base> p3(new base); +// p3 = p2; // should not compile + p3 = std::move(p2); +} + +void +test02() +{ + std::unique_ptr<int[]> p1(new int(420)); + std::unique_ptr<int[]> p2 = p1; // { dg-error "deleted" } +} + +void +test03() +{ + std::unique_ptr<int[2]> p1(new int[3]); // { dg-error "no match" } + // { dg-error "candidate" "candidate-note" { target *-*-* } 48 } + std::unique_ptr<int[2]> p2 = p1; // { dg-error "deleted" } +} + +// { dg-prune-output "include" } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/move.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/move.cc new file mode 100644 index 000000000..75529c969 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/move.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.11 Template class unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct B { virtual ~B() {} }; +struct D : public B {}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + D *d = new D; + std::unique_ptr<D> p1(d); + std::unique_ptr<D> p2(new D); + p2 = std::move(p1); + + VERIFY( p1.get() == 0 ); + VERIFY( p2.get() == d ); + + std::unique_ptr<B> p3(new B); + p3 = std::move(p2); + + VERIFY( p2.get() == 0 ); + VERIFY( p3.get() == d ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/move_array.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/move_array.cc new file mode 100644 index 000000000..b1b878d5d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/move_array.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.11 Template class unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct B { virtual ~B() {} }; +struct D : public B {}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + D *d = new D[3]; + std::unique_ptr<D[]> p1(d); + std::unique_ptr<D[]> p2; + p2 = std::move(p1); + + VERIFY( p1.get() == 0 ); + VERIFY( p2.get() == d ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/nullptr.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/nullptr.cc new file mode 100644 index 000000000..6f067ee4d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/nullptr.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.10 Class template unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A> p(new A); + p = nullptr; + + VERIFY( p.get() == nullptr ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A[]> p(new A[2]); + p = nullptr; + + VERIFY( p.get() == nullptr ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/comparison/42925.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/comparison/42925.cc new file mode 100644 index 000000000..e3dfad46f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/comparison/42925.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.10 Class template unique_ptr [unique.ptr] + +#include <memory> + +// libstdc++/42925 (also see GB 99) +void test01() +{ + std::unique_ptr<int> ptr; + if (ptr == 0) + { } + if (0 == ptr) + { } + if (ptr != 0) + { } + if (0 != ptr) + { } +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr.cc new file mode 100644 index 000000000..f4b9838d0 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.10 Class template unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.9.10.2.1 unique_ptr constructors [unique.ptr.single.ctor] + +// Construction from auto_ptr +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::auto_ptr<A> a(new A); + std::unique_ptr<A> a2(std::move(a)); + VERIFY( a.get() == nullptr ); + VERIFY( a2.get() != 0 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc new file mode 100644 index 000000000..76910c3c6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.10 Class template unique_ptr [unique.ptr] + +#include <memory> + +struct A { }; + +// 20.9.10.2.1 unique_ptr constructors [unique.ptr.single.ctor] + +// Construction from const auto_ptr +void +test01() +{ + const std::auto_ptr<A> a(new A); + std::unique_ptr<A> a2(std::move(a)); // { dg-error "no match" } +} +// { dg-excess-errors "candidates are" } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/constexpr.cc new file mode 100644 index 000000000..fbe9821f9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/constexpr.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x -fno-inline -save-temps -g0" } +// { dg-final { scan-assembler-not "_ZNSt10unique_ptrIiSt14default_deleteIiEEC2Ev" } } +// { dg-final { scan-assembler-not "_ZNSt10unique_ptrIiSt14default_deleteIiEEC2EDn" } } + +// 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_common_types.h> + +int main() +{ + __gnu_test::constexpr_default_constructible test1; //not literal + test1.operator()<std::unique_ptr<int>>(); + + __gnu_test::constexpr_single_value_constructible test2; //not literal + test2.operator()<std::unique_ptr<int>, std::nullptr_t>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/nullptr.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/nullptr.cc new file mode 100644 index 000000000..1f515ea53 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/nullptr.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.10 Class template unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A> p = nullptr; + + VERIFY( p.get() == nullptr ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A[]> p = nullptr; + + VERIFY( p.get() == nullptr ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer.cc new file mode 100644 index 000000000..324264b24 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer.cc @@ -0,0 +1,117 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.11 Template class unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + +// 20.6.11.2.1 unique_ptr constructors [unique.ptr.single.ctor] + +// Construction from pointer +void +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::unique_ptr<A> A_default; + VERIFY( A_default.get() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + std::unique_ptr<A> A_from_A(new A); + VERIFY( A_from_A.get() != 0 ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + std::unique_ptr<A> A_from_B(new B); + VERIFY( A_from_B.get() != 0 ); + VERIFY( A::ctor_count == 2 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); +} + +void +test02() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + A * const A_default = 0; + std::unique_ptr<A> p1(A_default); + VERIFY( p1.get() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + A * const A_from_A = new A; + std::unique_ptr<A> p2(A_from_A); + VERIFY( p2.get() == A_from_A ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer_array.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer_array.cc new file mode 100644 index 000000000..dcd6e92f1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer_array.cc @@ -0,0 +1,85 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + + +// 20.4.5.1 unique_ptr constructors [unique.ptr.cons] + +// Construction from pointer +void +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::unique_ptr<A[]> A_default; + VERIFY( A_default.get() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + std::unique_ptr<A[]> A_from_A(new A[3]); + VERIFY( A_from_A.get() != 0 ); + VERIFY( A::ctor_count == 3 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer_array_convertible_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer_array_convertible_neg.cc new file mode 100644 index 000000000..2a4a89b40 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer_array_convertible_neg.cc @@ -0,0 +1,41 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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> + +struct A +{ +}; + +struct B : A +{ + virtual ~B() { } +}; + +// 20.4.5.1 unique_ptr constructors [unique.ptr.cons] + +// Construction from pointer of derived type +void +test01() +{ + std::unique_ptr<B[]> B_from_A(new A[3]); //{ dg-error "invalid conversion from" } +} + +// { dg-prune-output "include" } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter.cc new file mode 100644 index 000000000..7e88eb948 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter.cc @@ -0,0 +1,68 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do run } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.10 Template class unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +static int count; + +void del(int* p) { ++count; delete p; } +void vdel(int* p) { ++count; delete[] p; } + +void +test01() +{ + bool test __attribute__((unused)) = true; + count = 0; + { + std::unique_ptr<int, void(*)(int*)> p(nullptr, del); + } + VERIFY( count == 0 ); + { + std::unique_ptr<int, void(*)(int*)> p(new int, del); + } + VERIFY( count == 1 ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + count = 0; + { + std::unique_ptr<int[], void(*)(int*)> p(nullptr, vdel); + } + VERIFY( count == 0 ); + { + std::unique_ptr<int[], void(*)(int*)> p(new int[1], vdel); + } + VERIFY( count == 1 ); +} + +int +main() +{ + test01(); + test02(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc new file mode 100644 index 000000000..e765874c7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.11 Template class unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +using std::unique_ptr; + +// { dg-excess-errors "static assertion failed" } + +void +test01() +{ + unique_ptr<int, void(*)(int*)> p1; // { dg-error "here" } + + unique_ptr<int, void(*)(int*)> p2(nullptr); // { dg-error "here" } + + unique_ptr<int, void(*)(int*)> p3(new int); // { dg-error "here" } +} + +void +test02() +{ + unique_ptr<int[], void(*)(int*)> p1; // { dg-error "here" } + + unique_ptr<int[], void(*)(int*)> p2(nullptr); // { dg-error "here" } + + unique_ptr<int[], void(*)(int*)> p3(new int[1]); // { dg-error "here" } +} + + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc new file mode 100644 index 000000000..53ece26ec --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-11 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> + +void test01() +{ + bool test __attribute__((unused)) = true; + + struct T { }; + + std::unique_ptr<T> u0(new T); + std::hash<std::unique_ptr<T>> hu0; + std::hash<typename std::unique_ptr<T>::pointer> hp0; + + VERIFY( hu0(u0) == hp0(u0.get()) ); + + std::unique_ptr<T[]> u1(new T[10]); + std::hash<std::unique_ptr<T[]>> hu1; + std::hash<typename std::unique_ptr<T[]>::pointer> hp1; + + VERIFY( hu1(u1) == hp1(u1.get()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc new file mode 100644 index 000000000..6dcf72919 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/43183.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation +// +// 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.9.10.2.5 unique_ptr modifiers [unique.ptr.single.modifiers] + +#include <memory> +#include <testsuite_hooks.h> + +struct D +{ + static int count; + + void operator()(int* p) const + { + ++count; + delete p; + } +}; +int D::count = 0; + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<int, D> up; + up.reset(); + VERIFY( D::count == 0 ); + up.reset(new int); + VERIFY( D::count == 0 ); + up.reset(up.get()); + VERIFY( D::count == 1 ); + up.release(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/48398.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/48398.cc new file mode 100644 index 000000000..54948df4b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/48398.cc @@ -0,0 +1,41 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2011 Free Software Foundation +// +// 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.7.1 Class template unique_ptr [unique.ptr] + +#include <memory> + +// PR libstdc++/48398 + +struct my_deleter +{ + typedef int* pointer; + + void operator()( pointer p ) { delete p; } +}; + +void test01() +{ + std::unique_ptr<void, my_deleter> p( new int() ); + + p.get(); + p.reset(); + +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc new file mode 100644 index 000000000..29bb57d22 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc @@ -0,0 +1,38 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009, 2010 Free Software Foundation +// +// 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> + +struct A +{ +}; + +struct B : A +{ + virtual ~B() { } +}; + +void test01() +{ + std::unique_ptr<B[]> up; + up.reset(new A[3]); // { dg-error "deleted" } +} + +// { dg-prune-output "include" } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/explicit_instantiation/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/explicit_instantiation/explicit_instantiation.cc new file mode 100644 index 000000000..dd308094b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/explicit_instantiation/explicit_instantiation.cc @@ -0,0 +1,24 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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> + +template class std::unique_ptr<int>; +template class std::unique_ptr<int[]>; diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/pointer_type.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/pointer_type.cc new file mode 100644 index 000000000..55f28caaa --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/pointer_type.cc @@ -0,0 +1,50 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010, 2011 Free Software Foundation +// +// 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.11 Template class unique_ptr [unique.ptr.single] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + void operator()(void*) const { } +}; + +struct B +{ + typedef char* pointer; + void operator()(pointer) const { } +}; + +int main() +{ + typedef std::unique_ptr<int> up; + typedef std::unique_ptr<int, A> upA; + typedef std::unique_ptr<int, B> upB; + typedef std::unique_ptr<int, A&> upAr; + typedef std::unique_ptr<int, B&> upBr; + + static_assert( std::is_same< up::pointer, int*>::value, "" ); + static_assert( std::is_same< upA::pointer, int*>::value, "" ); + static_assert( std::is_same< upB::pointer, char*>::value, "" ); + static_assert( std::is_same< upAr::pointer, int*>::value, "" ); + static_assert( std::is_same< upBr::pointer, char*>::value, "" ); +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/comparisons.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/comparisons.cc new file mode 100644 index 000000000..70bf90905 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/comparisons.cc @@ -0,0 +1,68 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.11 Template class unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + virtual ~A() { } +}; + +struct B : A +{ +}; + +// 20.6.11.5 unqiue_ptr specialized algorithms [unique.ptr.special] + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A> p1; + std::unique_ptr<A> p2; + + VERIFY( p1 == p2 ); + VERIFY( !(p1 != p2) ); + VERIFY( !(p1 < p2) && !(p1 > p2) ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A> p1; + std::unique_ptr<A> p2(new A); + + VERIFY( p1 != p2 ); + VERIFY( !(p1 == p2) ); + VERIFY( (p1 < p2) || (p1 > p2) ); + VERIFY( ((p1 <= p2) && (p1 != p2)) || ((p1 >= p2) && (p1 != p2)) ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/comparisons_array.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/comparisons_array.cc new file mode 100644 index 000000000..ccb429282 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/comparisons_array.cc @@ -0,0 +1,68 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.11 Template class unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A +{ + virtual ~A() { } +}; + +struct B : A +{ +}; + +// 20.6.11.5 unqiue_ptr specialized algorithms [unique.ptr.special] + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A[]> p1; + std::unique_ptr<A[]> p2; + + VERIFY( p1 == p2 ); + VERIFY( !(p1 != p2) ); + VERIFY( !(p1 < p2) && !(p1 > p2) ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A[]> p1; + std::unique_ptr<A[]> p2(new A[3]); + + VERIFY( p1 != p2 ); + VERIFY( !(p1 == p2) ); + VERIFY( (p1 < p2) || (p1 > p2) ); + VERIFY( ((p1 <= p2) && (p1 != p2)) || ((p1 >= p2) && (p1 != p2)) ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/swap.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/swap.cc new file mode 100644 index 000000000..fa0c31173 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/specialized_algorithms/swap.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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> + +struct A {}; + +//20.6.11.5 unique_ptr specialized algorithms [unique.ptr.special] + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A> p1; + std::unique_ptr<A> p2(new A); + std::unique_ptr<A> p3; + + std::swap(p3, p2); + + VERIFY( p1 != p3 ); + VERIFY( p2 != p3 ); + VERIFY( p1 == p2 ); +} + +int main() +{ + test01(); + return 0; +} 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 000000000..5a43088c4 --- /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 000000000..fad654d59 --- /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 000000000..5a7b0a8da --- /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 new file mode 100644 index 000000000..046fd3c6c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=gnu++0x " } +// { dg-do compile } + +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation +// +// 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.6.3 Template class weak_ptr [util.smartptr.weak] + +#include <memory> + +struct A { }; + +// 20.8.13.3.6 weak_ptr comparison [util.smartptr.weak.cmp] (removed) + +int +test01() +{ + std::weak_ptr<A> p1; + p1 < p1; // { dg-error "no match" } + // { dg-error "candidate" "candidate note" { target *-*-* } 33 } + return 0; +} + +int +main() +{ + test01(); + return 0; +} + +// { dg-warning "note" "" { target *-*-* } 358 } +// { dg-warning "note" "" { target *-*-* } 1086 } +// { dg-warning "note" "" { target *-*-* } 468 } +// { dg-warning "note" "" { target *-*-* } 586 } +// { dg-warning "note" "" { target *-*-* } 1049 } +// { dg-warning "note" "" { target *-*-* } 1055 } +// { dg-warning "note" "" { target *-*-* } 341 } +// { dg-warning "note" "" { target *-*-* } 291 } +// { dg-warning "note" "" { target *-*-* } 207 } diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/cons/constexpr.cc new file mode 100644 index 000000000..6e74dd35d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/cons/constexpr.cc @@ -0,0 +1,30 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x -fno-inline -save-temps -g0" } +// { dg-final { scan-assembler-not "_ZNSt8weak_ptrIiEC2Ev" } } + +// 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_common_types.h> + +int main() +{ + __gnu_test::constexpr_default_constructible test; //not literal + test.operator()<std::weak_ptr<int>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/lock/1.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/lock/1.cc new file mode 100644 index 000000000..ccaed290e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/lock/1.cc @@ -0,0 +1,36 @@ +// 2006-09-24 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2009 Free Software Foundation +// +// 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.6.3 Template class weak_ptr [util.smartptr.weak] + +#include <memory> +#include <testsuite_tr1.h> + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +int main() +{ + using __gnu_test::check_ret_type; + using std::weak_ptr; + using std::shared_ptr; + + weak_ptr<int> wp; + check_ret_type<shared_ptr<int> >(wp.lock()); +} diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc new file mode 100644 index 000000000..1081f93d3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/observers/owner_before.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// 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.8.13.3 Template class weak_ptr [util.smartptr.weak] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; +struct B { }; + +// 20.6.6.3.5 weak_ptr observers [util.smartptr.weak.obs] + +int +test01() +{ + bool test __attribute__((unused)) = true; + + // test empty weak_ptrs compare equivalent + std::weak_ptr<A> p1; + std::weak_ptr<B> p2; + VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) ); + + std::shared_ptr<B> p3; + VERIFY( !p1.owner_before(p3) && !p3.owner_before(p1) ); + + return 0; +} + + +int +test02() +{ + bool test __attribute__((unused)) = true; + + std::shared_ptr<A> a0; + std::weak_ptr<A> w0(a0); + + std::shared_ptr<A> a1(new A); + std::weak_ptr<A> w1(a1); + VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) ); + + VERIFY( w1.owner_before(w0) || w0.owner_before(w1) ); + VERIFY( !(w1.owner_before(w0) && w0.owner_before(w1)) ); + + VERIFY( w1.owner_before(a0) || a0.owner_before(w1) ); + VERIFY( !(w1.owner_before(a0) && a0.owner_before(w1)) ); + + std::shared_ptr<B> b1(new B); + VERIFY( w1.owner_before(b1) || b1.owner_before(w1) ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..ebfc94351 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/requirements/explicit_instantiation/1.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2006, 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_tr1.h> + +using namespace __gnu_test; +using std::weak_ptr; +template class weak_ptr<int>; +template class weak_ptr<void>; +template class weak_ptr<ClassType>; +template class weak_ptr<IncompleteClass>; diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..db49600b8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/requirements/explicit_instantiation/2.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 2009 Free Software Foundation +// +// 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.6.2 Template class shared_ptr [util.smartptr.shared] + +#include <memory> +#include <testsuite_tr1.h> + +// Check the _S_single lock policy can be instantiated. For a thread-enabled +// library this checks the templates can be instantiated for non-default +// lock policy, for a single-threaded lib this is redundant but harmless. +using namespace __gnu_test; +using std::__weak_ptr; +using std::_S_single; +template class __weak_ptr<int, _S_single>; +template class __weak_ptr<void, _S_single>; +template class __weak_ptr<ClassType, _S_single>; +template class __weak_ptr<IncompleteClass, _S_single>; |