]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 2017-2022 Free Software Foundation, Inc. |
a3a1620b JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-do compile { target c++11 } } | |
19 | ||
20 | #include <memory> | |
21 | ||
22 | using std::is_same; | |
23 | ||
24 | template<typename T, typename U> | |
25 | using Rebind = typename std::allocator_traits<T>::template rebind_alloc<U>; | |
26 | ||
64c986b4 | 27 | template<typename T, typename = T> |
a3a1620b JW |
28 | struct HasRebind { |
29 | using value_type = T; | |
64c986b4 | 30 | template<typename U> struct rebind { using other = HasRebind<U>; }; |
a3a1620b JW |
31 | }; |
32 | ||
64c986b4 JW |
33 | // Would get HasRebind<long, int> here if the first template argument is |
34 | // replaced instead of using the nested rebind. | |
35 | static_assert(is_same<Rebind<HasRebind<int>, long>, HasRebind<long>>::value, | |
a3a1620b JW |
36 | "nested alias template is used"); |
37 | ||
38 | template<typename T> | |
39 | struct NoRebind0 { | |
40 | using value_type = T; | |
41 | }; | |
42 | ||
43 | static_assert(is_same<Rebind<NoRebind0<int>, long>, | |
44 | NoRebind0<long>>::value, | |
45 | "first template argument is replaced"); | |
46 | ||
47 | template<typename T, typename> | |
48 | struct NoRebind1 { | |
49 | using value_type = T; | |
50 | }; | |
51 | ||
52 | static_assert(is_same<Rebind<NoRebind1<int, void>, long>, | |
53 | NoRebind1<long, void>>::value, | |
54 | "first template argument is replaced"); | |
55 | ||
56 | template<typename T, typename, typename> | |
57 | struct NoRebind2 { | |
58 | using value_type = T; | |
59 | }; | |
60 | ||
61 | static_assert(is_same<Rebind<NoRebind2<int, void, void>, long>, | |
62 | NoRebind2<long, void, void>>::value, | |
63 | "first template argument is replaced"); | |
64 | ||
65 | template<typename T, typename...> | |
66 | struct NoRebindN { | |
67 | using value_type = T; | |
68 | }; | |
69 | ||
70 | static_assert(is_same<Rebind<NoRebindN<int>, long>, | |
71 | NoRebindN<long>>::value, | |
72 | "first template argument is replaced"); | |
73 | static_assert(is_same<Rebind<NoRebindN<int, void>, long>, | |
74 | NoRebindN<long, void>>::value, | |
75 | "first template argument is replaced"); | |
76 | ||
77 | template<typename T, int = 0> | |
78 | struct CannotRebind { | |
79 | using value_type = T; | |
80 | }; | |
81 | // PR libstdc++/72792 specialization of allocator_traits is still well-formed: | |
82 | std::allocator_traits<CannotRebind<int>>::value_type v; |