[libcxx-commits] [libcxx] [libc++][regex] Fix #51028 throw exception in the case of wrong range (PR #148231)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 18 08:58:22 PDT 2025


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/148231

>From 09f38bc2eb158f6268dc687d0c99eb462f5c7996 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/regex                                         | 2 +-
 .../std/re/re.regex/re.regex.construct/bad_range.pass.cpp    | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/regex b/libcxx/include/regex
index bbc21e244dd17..9bbc3a69021b9 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 || char_traits<typename string_type::value_type>::lt(__e[0], __b[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..ecfdaee2eed66 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
@@ -14,6 +14,8 @@
 // template <class ST, class SA>
 //    basic_regex(const basic_string<charT, ST, SA>& s);
 
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
 #include <regex>
 #include <cassert>
 #include "test_macros.h"
@@ -33,6 +35,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