deduct.fail.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // <queue>
  9. // UNSUPPORTED: c++98, c++03, c++11, c++14
  10. // UNSUPPORTED: libcpp-no-deduction-guides
  11. #include <queue>
  12. #include <deque>
  13. #include <iterator>
  14. #include <cassert>
  15. #include <cstddef>
  16. int main(int, char**)
  17. {
  18. // Test the explicit deduction guides
  19. {
  20. // queue(Compare, Container, const Alloc);
  21. // The '45' is not an allocator
  22. std::priority_queue pri(std::greater<int>(), std::deque<int>({1,2,3}), 45); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'priority_queue'}}
  23. }
  24. {
  25. // queue(const queue&, const Alloc&);
  26. // The '45' is not an allocator
  27. std::priority_queue<int> source;
  28. std::priority_queue pri(source, 45); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'priority_queue'}}
  29. }
  30. {
  31. // priority_queue(Iter, Iter, Comp)
  32. // int is not an iterator
  33. std::priority_queue pri(15, 17, std::greater<double>()); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'priority_queue'}}
  34. }
  35. {
  36. // priority_queue(Iter, Iter, Comp, Container)
  37. // float is not an iterator
  38. std::priority_queue pri(23.f, 2.f, std::greater<float>(), std::deque<float>()); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'priority_queue'}}
  39. }
  40. // Test the implicit deduction guides
  41. {
  42. // priority_queue (allocator &)
  43. std::priority_queue pri((std::allocator<int>())); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'priority_queue'}}
  44. // Note: The extra parens are necessary, since otherwise clang decides it is a function declaration.
  45. // Also, we can't use {} instead of parens, because that constructs a
  46. // stack<allocator<int>, allocator<allocator<int>>>
  47. }
  48. return 0;
  49. }