[libcxx-commits] [libcxx] [libc++][regex] Fix #51028 throw exception in the case of wrong range (PR #148231)
Lazarev Alexei via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 11 05:12:52 PDT 2025
https://github.com/insanustu updated https://github.com/llvm/llvm-project/pull/148231
>From 988130cce90ab3343862fbec1b68a73cfc64dd3c Mon Sep 17 00:00:00 2001
From: "alexey.lazarev" <alexey.lazarev at tasking.com>
Date: Fri, 11 Jul 2025 13:16:14 +0200
Subject: [PATCH] [libc++][regex] Fix #51028 throw exception in the case of
wrong range
---
libcxx/include/__cxx03/regex | 2 +-
libcxx/include/regex | 2 +-
.../test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp | 3 ++-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/libcxx/include/__cxx03/regex b/libcxx/include/__cxx03/regex
index b96d59d3a252a..fcf44f49b60da 100644
--- a/libcxx/include/__cxx03/regex
+++ b/libcxx/include/__cxx03/regex
@@ -2100,7 +2100,7 @@ public:
__ranges_.push_back(
std::make_pair(__traits_.transform(__b.begin(), __b.end()), __traits_.transform(__e.begin(), __e.end())));
} else {
- if (__b.size() != 1 || __e.size() != 1)
+ if (__b.size() != 1 || __e.size() != 1 || __b[0] > __e[0])
__throw_regex_error<regex_constants::error_range>();
if (__icase_) {
__b[0] = __traits_.translate_nocase(__b[0]);
diff --git a/libcxx/include/regex b/libcxx/include/regex
index bbc21e244dd17..958168a88535d 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -2120,7 +2120,7 @@ public:
__ranges_.push_back(
std::make_pair(__traits_.transform(__b.begin(), __b.end()), __traits_.transform(__e.begin(), __e.end())));
} else {
- if (__b.size() != 1 || __e.size() != 1)
+ if (__b.size() != 1 || __e.size() != 1 || __b[0] > __e[0])
std::__throw_regex_error<regex_constants::error_range>();
if (__icase_) {
__b[0] = __traits_.translate_nocase(__b[0]);
diff --git a/libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp b/libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp
index 023bc0ee79f44..cabd9ebec520e 100644
--- a/libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp
+++ b/libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp
@@ -33,6 +33,7 @@ int main(int, char**)
{
assert(error_range_thrown("([\\w-a])"));
assert(error_range_thrown("([a-\\w])"));
+ assert(error_range_thrown("([w-a])"));
- return 0;
+ return 0;
}
More information about the libcxx-commits
mailing list