you*_*hao 8 c++ c++-standard-library c++11 clang++
按照标准规定:
match_prev_avail:--first是有效的迭代器位置。设置后,将忽略match_not_bol和match_not_bow
但是我运行以下代码并得到:
#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;
}
Run Code Online (Sandbox Code Playgroud)
输出:
0
1
0
Run Code Online (Sandbox Code Playgroud)
似乎已match_prev_avail被覆盖match_not_bol。
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
Run Code Online (Sandbox Code Playgroud)
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)