Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong implementation for regex_constants in clang?

As specified in the standard:

match_prev_avail: --first is a valid iterator position. When set, causes match_not_bol and match_not_bow to be ignored

But I run the following code and get:

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

int main()
{
    regex re0("^bcd");
    string str = "abcd";
    std::string::iterator start = str.begin() + 1;
    cout << regex_search(start, str.end(), re0, regex_constants::match_not_bol) << endl;
    cout << regex_search(start, str.end(), re0, regex_constants::match_prev_avail) << endl;
    cout << regex_search(start, str.end(), re0, regex_constants::match_prev_avail | regex_constants::match_not_bol) << endl;
}

output:

0
1
0

It seems that match_prev_avail is overwritten by match_not_bol.

like image 959
youkaichao Avatar asked Jun 08 '19 10:06

youkaichao


1 Answers

Seems you found a bug in clang. (file it here: https://bugs.llvm.org/ as it seems not yet have been reported)

I checked MSVC 1914 and it gives

0
0
0

same as GCC 4.9.2 (used cpp.sh to check)

I rechecked the .pdf form of the standard (N4810) and this in 30.5.2 matches what the cppreference states.

match_prev_avail: --first is a valid iterator position. When this flag is set the flags match_not_bol and match_not_bow shall be ignored by the regular expression algorithms (30.11) and iterators (30.12)

like image 113
skeller Avatar answered Oct 18 '22 20:10

skeller