iter_alloc_deduction.fail.cpp (2300B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <string> 11 // UNSUPPORTED: c++98, c++03, c++11, c++14 12 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8, clang-3.9, clang-4.0 13 // UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9 14 15 // template<class InputIterator, 16 // class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 17 // basic_string(InputIterator, InputIterator, Allocator = Allocator()) 18 // -> basic_string<typename iterator_traits<InputIterator>::value_type, 19 // char_traits<typename iterator_traits<InputIterator>::value_type>, 20 // Allocator>; 21 // 22 // The deduction guide shall not participate in overload resolution if InputIterator 23 // is a type that does not qualify as an input iterator, or if Allocator is a type 24 // that does not qualify as an allocator. 25 26 27 #include <string> 28 #include <iterator> 29 #include <cassert> 30 #include <cstddef> 31 32 #include "test_macros.h" 33 34 class NotAnItertor {}; 35 36 template <typename T> 37 struct NotAnAllocator { typedef T value_type; }; 38 39 int main() 40 { 41 { // Not an iterator at all 42 std::basic_string s1{NotAnItertor{}, NotAnItertor{}, std::allocator<char>{}}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_string'}} 43 } 44 { // Not an input iterator 45 const char16_t* s = u"12345678901234"; 46 std::basic_string<char16_t> s0; 47 std::basic_string s1{std::back_insert_iterator(s0), // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_string'}} 48 std::back_insert_iterator(s0), 49 std::allocator<char16_t>{}}; 50 } 51 { // Not an allocator 52 const wchar_t* s = L"12345678901234"; 53 std::basic_string s1{s, s+10, NotAnAllocator<wchar_t>{}}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_string'}} 54 } 55 56 }