PR libstdc++/87278 restore support for std::make_shared<volatile T>()
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / shared_ptr / comparison / less.cc
blob81c138a5aafb3a8a00512214759b9b66569cc38b
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2008-2018 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 20.8.13.2 Template class shared_ptr [util.smartptr.shared]
22 #include <memory>
23 #include <testsuite_hooks.h>
25 struct A { };
27 namespace std
29 template<>
30 struct less<A*> : binary_function<A*,A*,bool>
32 static int count;
33 bool operator()(A* l, A* r) { ++count; return l < r; }
35 int less<A*>::count = 0;
38 // 20.8.13.2.7 shared_ptr comparison [util.smartptr.shared.cmp]
41 int
42 test01()
44 std::less<std::shared_ptr<A>> less;
45 // test empty shared_ptrs compare equivalent
46 std::shared_ptr<A> p1;
47 std::shared_ptr<A> p2;
48 VERIFY( !less(p1, p2) && !less(p2, p1) );
49 VERIFY( std::less<A*>::count == 2 );
50 return 0;
54 // Construction from pointer
55 int
56 test02()
58 std::less<std::shared_ptr<A>> less;
60 std::shared_ptr<A> empty;
61 std::shared_ptr<A> p1(new A);
62 std::shared_ptr<A> p2(new A);
64 VERIFY( less(p1, p2) || less(p2, p1) );
65 VERIFY( !(less(p1, p2) && less(p2, p1)) );
67 p1.reset();
68 VERIFY( !less(p1, empty) && !less(empty, p1) );
70 p2.reset();
71 VERIFY( !less(p1, p2) && !less(p2, p1) );
73 return 0;
76 // Aliasing
77 int
78 test03()
80 std::less<std::shared_ptr<A>> less;
82 A a;
83 std::shared_ptr<A> p1(new A);
84 std::shared_ptr<A> p2(p1, &a);
85 VERIFY( less(p1, p2) || less(p2, p1) );
87 return 0;
89 int
90 main()
92 test01();
93 test02();
94 test03();
95 return 0;