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

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 1 03:00:16 PST 2025


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

>From 2855a30a6238cb5184e0301a49d9d728497c2f0c Mon Sep 17 00:00:00 2001
From: Austin <zhenhangwang at huawei.com>
Date: Sat, 1 Mar 2025 10:37:20 +0800
Subject: [PATCH] [regex] fix uncaught exception when string is like "\\_"

fixes #129062
---
 libcxx/include/regex                                        | 2 +-
 libcxx/test/std/re/re.regex/re.regex.construct/ptr.pass.cpp | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/regex b/libcxx/include/regex
index 36ea55ce30921..6916f91628821 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -3954,7 +3954,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
       ++__first;
       break;
     default:
-      if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) {
+      if (!__traits_.isctype(*__first, ctype_base::alnum)) {
         if (__str)
           *__str = *__first;
         else
diff --git a/libcxx/test/std/re/re.regex/re.regex.construct/ptr.pass.cpp b/libcxx/test/std/re/re.regex/re.regex.construct/ptr.pass.cpp
index b71d9eb7f497c..a23900d44528e 100644
--- a/libcxx/test/std/re/re.regex/re.regex.construct/ptr.pass.cpp
+++ b/libcxx/test/std/re/re.regex/re.regex.construct/ptr.pass.cpp
@@ -31,6 +31,7 @@ int main(int, char**)
     test("\\(a[bc]\\)", 0);
     test("\\(a\\([bc]\\)\\)", 0);
     test("(a([bc]))", 2);
+    test("\\$\\_se", 0);
 
   return 0;
 }



More information about the libcxx-commits mailing list