| 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 | // <set> |
| 12 | |
| 13 | // template<class InputIterator, |
| 14 | // class Compare = less<iter-value-type<InputIterator>>, |
| 15 | // class Allocator = allocator<iter-value-type<InputIterator>>> |
| 16 | // set(InputIterator, InputIterator, |
| 17 | // Compare = Compare(), Allocator = Allocator()) |
| 18 | // -> set<iter-value-type<InputIterator>, Compare, Allocator>; |
| 19 | // template<class Key, class Compare = less<Key>, |
| 20 | // class Allocator = allocator<Key>> |
| 21 | // set(initializer_list<Key>, Compare = Compare(), Allocator = Allocator()) |
| 22 | // -> set<Key, Compare, Allocator>; |
| 23 | // template<class InputIterator, class Allocator> |
| 24 | // set(InputIterator, InputIterator, Allocator) |
| 25 | // -> set<iter-value-type<InputIterator>, |
| 26 | // less<iter-value-type<InputIterator>>, Allocator>; |
| 27 | // template<class Key, class Allocator> |
| 28 | // set(initializer_list<Key>, Allocator) |
| 29 | // -> set<Key, less<Key>, Allocator>; |
| 30 | |
| 31 | #include <functional> |
| 32 | #include <set> |
| 33 | #include <type_traits> |
| 34 | |
| 35 | struct NotAnAllocator { |
| 36 | friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; } |
| 37 | }; |
| 38 | |
| 39 | int main(int, char**) { |
| 40 | { |
| 41 | // cannot deduce Key from nothing |
| 42 | std::set s; |
| 43 | // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}set'}} |
| 44 | } |
| 45 | { |
| 46 | // cannot deduce Key from just (Compare) |
| 47 | std::set s(std::less<int>{}); |
| 48 | // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}set'}} |
| 49 | } |
| 50 | { |
| 51 | // cannot deduce Key from just (Compare, Allocator) |
| 52 | std::set s(std::less<int>{}, std::allocator<int>{}); |
| 53 | // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}set'}} |
| 54 | } |
| 55 | { |
| 56 | // cannot deduce Key from just (Allocator) |
| 57 | std::set s(std::allocator<int>{}); |
| 58 | // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}set'}} |
| 59 | } |
| 60 | { |
| 61 | // since we have parens, not braces, this deliberately does not find the |
| 62 | // initializer_list constructor |
| 63 | NotAnAllocator a; |
| 64 | std::set s(a); |
| 65 | // expected-error-re@-1{{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}set'}} |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |