Skip to content

[regex] fix uncaught exception when string is like "\\_" #129348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

Zhenhang1213
Copy link
Contributor

@Zhenhang1213 Zhenhang1213 commented Mar 1, 2025

\_ is a valid identity escape in regular expressions, but previously libc++ incorrectly treated it as invalid. So I deleted this judgment
fixes #129062

@Zhenhang1213 Zhenhang1213 requested a review from a team as a code owner March 1, 2025 02:43
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 1, 2025

@llvm/pr-subscribers-libcxx

Author: Austin (Zhenhang1213)

Changes

fixes #129062


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

1 Files Affected:

  • (modified) libcxx/include/regex (+1-1)
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

@Zhenhang1213
Copy link
Contributor Author

@frederick-vs-ja where could I find those tests?

@frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja where could I find those tests?

I think we can add a new case to libcxx/test/std/re/re.regex/re.regex.construct/ptr.pass.cpp.

Copy link

github-actions bot commented Mar 1, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I've some comments.

@mordante mordante self-assigned this Mar 3, 2025
@Zhenhang1213 Zhenhang1213 force-pushed the fix_libc++ branch 2 times, most recently from d7c42f1 to dfd5830 Compare March 4, 2025 06:08
@Zhenhang1213 Zhenhang1213 requested a review from mordante March 8, 2025 01:42
@Zhenhang1213 Zhenhang1213 force-pushed the fix_libc++ branch 3 times, most recently from 5fe7f21 to 3c29eb9 Compare March 8, 2025 07:20
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question: why didn't you rebase the branch onto the head of llvm:main while rebasing many times?

@mordante mordante mentioned this pull request Mar 8, 2025
@Zhenhang1213
Copy link
Contributor Author

Just a question: why didn't you rebase the branch onto the head of llvm:main while rebasing many times?

Right, I update it

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

Do you need somebody to land this patch for you?

@hstk30-hw hstk30-hw merged commit 9d7ca6c into llvm:main Mar 11, 2025
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc++] regex uncaught exception using libc++, but libstdc++ not
5 participants