[libcxx-commits] [libcxx] 77f0a7d - [libc++][regex] Throw exception in the case of wrong range (#148231)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 21 05:41:03 PDT 2025


Author: Lazarev Alexei
Date: 2025-07-21T20:41:00+08:00
New Revision: 77f0a7de3e648e8507572b71990dc3373cd460f2

URL: https://github.com/llvm/llvm-project/commit/77f0a7de3e648e8507572b71990dc3373cd460f2
DIFF: https://github.com/llvm/llvm-project/commit/77f0a7de3e648e8507572b71990dc3373cd460f2.diff

LOG: [libc++][regex] Throw exception in the case of wrong range (#148231)

Starting and ending parameters are considered to decide that a range is
a correct one

Fix #51028

Co-authored-by: alexey.lazarev <alexey.lazarev at tasking.com>
Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>

Added: 
    

Modified: 
    libcxx/include/regex
    libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp

Removed: 
    


################################################################################
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