[libcxx-commits] [libcxx] [regex] fix uncaught exception when string is like "\\_" (PR #129348)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 9 09:11:26 PDT 2025


================
@@ -669,6 +671,21 @@ int main(int, char**)
         assert(m.position(0) == 0);
         assert(m.str(0) == s);
     }
+    {
+      std::cmatch m;
+      const char s[] = "$_se";
+      assert(std::regex_match(s, m, std::regex("\\$\\_se")));
+      assert(m.size() == 1);
+      assert(!m.prefix().matched);
+      assert(m.prefix().first == s);
+      assert(m.prefix().second == m[0].first);
+      assert(!m.suffix().matched);
+      assert(m.suffix().first == m[0].second);
+      assert(m.suffix().second == s + std::char_traits<char>::length(s));
+      assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
+      assert(m.position(0) == 0);
+      assert(m.str(0) == s);
+    }
----------------
frederick-vs-ja wrote:

Could you copy these lines into the `TEST_HAS_NO_WIDE_CHARACTERS` part with the character type changed to `wchar_t`?

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


More information about the libcxx-commits mailing list