backup.pass.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // <regex>
  9. // template <class BidirectionalIterator, class Allocator, class charT, class traits>
  10. // bool
  11. // regex_search(BidirectionalIterator first, BidirectionalIterator last,
  12. // match_results<BidirectionalIterator, Allocator>& m,
  13. // const basic_regex<charT, traits>& e,
  14. // regex_constants::match_flag_type flags = regex_constants::match_default);
  15. #include <regex>
  16. #include <string>
  17. #include <list>
  18. #include <cassert>
  19. #include "test_macros.h"
  20. int main(int, char**)
  21. {
  22. // This regex_iterator uses regex_search(__wrap_iter<_Iter> __first, ...)
  23. // Test for https://bugs.llvm.org/show_bug.cgi?id=16240 fixed in r185273.
  24. {
  25. std::string s("aaaa a");
  26. std::regex re("\\ba");
  27. std::sregex_iterator it(s.begin(), s.end(), re);
  28. std::sregex_iterator end = std::sregex_iterator();
  29. assert(it->position(0) == 0);
  30. assert(it->length(0) == 1);
  31. ++it;
  32. assert(it->position(0) == 5);
  33. assert(it->length(0) == 1);
  34. ++it;
  35. assert(it == end);
  36. }
  37. // This regex_iterator uses regex_search(_BidirectionalIterator __first, ...)
  38. {
  39. std::string s("aaaa a");
  40. std::list<char> l(s.begin(), s.end());
  41. std::regex re("\\ba");
  42. std::regex_iterator<std::list<char>::iterator> it(l.begin(), l.end(), re);
  43. std::regex_iterator<std::list<char>::iterator> end = std::regex_iterator<std::list<char>::iterator>();
  44. assert(it->position(0) == 0);
  45. assert(it->length(0) == 1);
  46. ++it;
  47. assert(it->position(0) == 5);
  48. assert(it->length(0) == 1);
  49. ++it;
  50. assert(it == end);
  51. }
  52. return 0;
  53. }