iter_alloc_deduction.fail.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // <string>
  9. // UNSUPPORTED: c++98, c++03, c++11, c++14
  10. // 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
  11. // UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9
  12. // template<class InputIterator,
  13. // class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
  14. // basic_string(InputIterator, InputIterator, Allocator = Allocator())
  15. // -> basic_string<typename iterator_traits<InputIterator>::value_type,
  16. // char_traits<typename iterator_traits<InputIterator>::value_type>,
  17. // Allocator>;
  18. //
  19. // The deduction guide shall not participate in overload resolution if InputIterator
  20. // is a type that does not qualify as an input iterator, or if Allocator is a type
  21. // that does not qualify as an allocator.
  22. #include <string>
  23. #include <iterator>
  24. #include <cassert>
  25. #include <cstddef>
  26. #include "test_macros.h"
  27. class NotAnItertor {};
  28. template <typename T>
  29. struct NotAnAllocator { typedef T value_type; };
  30. int main(int, char**)
  31. {
  32. { // Not an iterator at all
  33. 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'}}
  34. }
  35. { // Not an input iterator
  36. const char16_t* s = u"12345678901234";
  37. std::basic_string<char16_t> s0;
  38. 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'}}
  39. std::back_insert_iterator(s0),
  40. std::allocator<char16_t>{}};
  41. }
  42. { // Not an allocator
  43. const wchar_t* s = L"12345678901234";
  44. 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'}}
  45. }
  46. return 0;
  47. }