Skip to content

[libc++] std::regex match_prev_avail implementation is regressed #74838

Open
@zufuliu

Description

@zufuliu

It seems match_prev_avail implementation is regressed after fixed issue #41544.

test cases:

#include <string>
#include <regex>
#include <iostream>
using namespace std;

int main() {
    string s = "ab";
    string::iterator start = s.begin() + 1;
    regex re0("^");
    cout << "^" << endl;
    cout << regex_search(start, s.end(), re0, regex_constants::match_default) << endl;
    cout << regex_search(start, s.end(), re0, regex_constants::match_not_bol) << endl;
    cout << regex_search(start, s.end(), re0, regex_constants::match_prev_avail) << endl;
    cout << regex_search(start, s.end(), re0, regex_constants::match_prev_avail | regex_constants::match_not_bol) << endl;

    // https://github.com/llvm/llvm-project/issues/41544
    regex re1("^ab");
    cout << "\n\n" << "^ab" << endl;
    cout << regex_search(s, re1, regex_constants::match_default) << endl;
    cout << regex_search(s, re1, regex_constants::match_not_bol) << endl;
    cout << regex_search(s, re1, regex_constants::match_prev_avail) << endl;
    cout << regex_search(s, re1, regex_constants::match_prev_avail | regex_constants::match_not_bol) << endl;

    regex re2("^b");
    cout << "\n\n" << "^b" << endl;
    cout << regex_search(start, s.end(), re2, regex_constants::match_default) << endl;
    cout << regex_search(start, s.end(), re2, regex_constants::match_not_bol) << endl;
    cout << regex_search(start, s.end(), re2, regex_constants::match_prev_avail) << endl;
    cout << regex_search(start, s.end(), re2, regex_constants::match_prev_avail | regex_constants::match_not_bol) << endl;
    return 0;
}

GCC (msys2 mingw64 13.2.0):

D:\notepad2>g++ -std=c++17 -Wall -Wextra test.cpp

D:\notepad2>a.exe
^
1
0
0
0


^ab
1
0
0
0


^b
1
0
0
0

MSVC (2022 17.8.3):

D:\notepad2>cl /nologo /EHsc /std:c++17 /W4 test.cpp
test.cpp

D:\notepad2>test.exe
^
1
0
0
0


^ab
1
0
0
0


^b
1
0
0
0

llvm-mingw 17.0.6 https://github.com/mstorsjo/llvm-mingw/releases/tag/20231128

D:\notepad2>clang++ -std=c++17 -Wall -Wextra test.cpp

D:\notepad2>a.exe
^
1
0
1
1


^ab
1
0
1
1


^b
1
0
1
1

based on https://sourceforge.net/p/scintilla/bugs/2405/?page=1#442d/89d2, libc++ (Xcode 15.0.1) on macOS also fails.

Metadata

Metadata

Labels

libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.regexIssues related to regexregression

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions