| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14 |
| 10 |
|
| 11 |
// <map> |
| 12 |
|
| 13 |
// template<class InputIterator, |
| 14 |
// class Compare = less<iter-value-type<InputIterator>>, |
| 15 |
// class Allocator = allocator<iter-value-type<InputIterator>>> |
| 16 |
// map(InputIterator, InputIterator, |
| 17 |
// Compare = Compare(), Allocator = Allocator()) |
| 18 |
// -> map<iter-value-type<InputIterator>, Compare, Allocator>; |
| 19 |
// template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>> |
| 20 |
// map(initializer_list<Key>, Compare = Compare(), Allocator = Allocator()) |
| 21 |
// -> map<Key, Compare, Allocator>; |
| 22 |
// template<class InputIterator, class Allocator> |
| 23 |
// map(InputIterator, InputIterator, Allocator) |
| 24 |
// -> map<iter-value-type<InputIterator>, less<iter-value-type<InputIterator>>, Allocator>; |
| 25 |
// template<class Key, class Allocator> |
| 26 |
// map(initializer_list<Key>, Allocator) |
| 27 |
// -> map<Key, less<Key>, Allocator>; |
| 28 |
|
| 29 |
#include <climits> // INT_MAX |
| 30 |
#include <functional> |
| 31 |
#include <map> |
| 32 |
#include <type_traits> |
| 33 |
|
| 34 |
struct NotAnAllocator { |
| 35 |
friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; } |
| 36 |
}; |
| 37 |
|
| 38 |
using P = std::pair<int, long>; |
| 39 |
using PC = std::pair<const int, long>; |
| 40 |
|
| 41 |
int main(int, char**) |
| 42 |
{ |
| 43 |
{ |
| 44 |
// cannot deduce Key and T from nothing |
| 45 |
std::map m; // expected-error-re {{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 46 |
} |
| 47 |
{ |
| 48 |
// cannot deduce Key and T from just (Compare) |
| 49 |
std::map m(std::less<int>{}); |
| 50 |
// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 51 |
} |
| 52 |
{ |
| 53 |
// cannot deduce Key and T from just (Compare, Allocator) |
| 54 |
std::map m(std::less<int>{}, std::allocator<PC>{}); |
| 55 |
// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 56 |
} |
| 57 |
{ |
| 58 |
// cannot deduce Key and T from just (Allocator) |
| 59 |
std::map m(std::allocator<PC>{}); |
| 60 |
// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 61 |
} |
| 62 |
{ |
| 63 |
// refuse to rebind the allocator if Allocator::value_type is not exactly what we expect |
| 64 |
const P arr[] = { {1,1L}, {2,2L}, {3,3L} }; |
| 65 |
std::map m(arr, arr + 3, std::allocator<P>()); |
| 66 |
// expected-error-re@map:*{{static assertion failed{{( due to requirement '.*')?}}{{.*}}Allocator::value_type must be same type as value_type}} |
| 67 |
} |
| 68 |
{ |
| 69 |
// cannot convert from some arbitrary unrelated type |
| 70 |
NotAnAllocator a; |
| 71 |
std::map m(a); // expected-error-re{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 72 |
} |
| 73 |
{ |
| 74 |
// cannot deduce that the inner braced things should be std::pair and not something else |
| 75 |
std::map m{ {1,1L}, {2,2L}, {3,3L} }; |
| 76 |
// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 77 |
} |
| 78 |
{ |
| 79 |
// cannot deduce that the inner braced things should be std::pair and not something else |
| 80 |
std::map m({ {1,1L}, {2,2L}, {3,3L} }, std::less<int>()); |
| 81 |
// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 82 |
} |
| 83 |
{ |
| 84 |
// cannot deduce that the inner braced things should be std::pair and not something else |
| 85 |
std::map m({ {1,1L}, {2,2L}, {3,3L} }, std::less<int>(), std::allocator<PC>()); |
| 86 |
// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 87 |
} |
| 88 |
{ |
| 89 |
// cannot deduce that the inner braced things should be std::pair and not something else |
| 90 |
std::map m({ {1,1L}, {2,2L}, {3,3L} }, std::allocator<PC>()); |
| 91 |
// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 92 |
} |
| 93 |
{ |
| 94 |
// since we have parens, not braces, this deliberately does not find the initializer_list constructor |
| 95 |
std::map m(P{1,1L}); |
| 96 |
// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 97 |
} |
| 98 |
{ |
| 99 |
// since we have parens, not braces, this deliberately does not find the initializer_list constructor |
| 100 |
std::map m(PC{1,1L}); |
| 101 |
// expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}map'}} |
| 102 |
} |
| 103 |
|
| 104 |
return 0; |
| 105 |
} |