[libcxx-commits] [libcxx] [libc++] Fix `regex_search` to match `$` alone with `match_default` flag (PR #78845)

Sanjay Marreddi via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 20 09:14:52 PST 2024


================
@@ -47,5 +47,33 @@ int main(int, char**)
     assert( std::regex_search(target, re, std::regex_constants::match_not_eol));
     }
 
+    {
+      std::string target = "foo";
+      std::regex re("$");
+      assert(std::regex_search(target, re));
+      assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));
+
+      std::smatch match;
+      assert(std::regex_search(target, match, re));
+      assert(match.position(0) == 3);
+      assert(match.length(0) == 0);
+      assert(!std::regex_search(target, match, re, std::regex_constants::match_not_eol));
+      assert(match.length(0) == 0);
+    }
+
+    {
+      std::string target = "foo";
+      std::regex re("$");
+      assert(!std::regex_match(target, re));
+      assert(!std::regex_match(target, re, std::regex_constants::match_not_eol));
+    }
+
+    {
+      std::string target = "a";
+      std::regex re{"^b*$"};
----------------
SanjayMarreddi wrote:

- Updated the test.
- Yeah, I tested in the C++03 mode using the above command specifying the param. The tests are passing locally.



https://github.com/llvm/llvm-project/pull/78845


More information about the libcxx-commits mailing list