首页 > 解决方案 > clang 中 regex_constants 的错误实现?

问题描述

标准中规定:

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;
}

输出:

0
1
0

似乎match_prev_avail被覆盖了match_not_bol

标签: c++c++11clang++c++-standard-library

解决方案


似乎您在 clang 中发现了一个错误。(在这里归档:https ://bugs.llvm.org/ ,因为它似乎还没有被报告)

我检查了 MSVC 1914,它给出了

0
0
0

与 GCC 4.9.2 相同(使用 cpp.sh 检查)

我重新检查了标准 (N4810) 的 .pdf 格式,这在 30.5.2 中与cppreference状态相符。

match_prev_avail: --first 是一个有效的迭代器位置。当设置此标志时,正则表达式算法 (30.11) 和迭代器 (30.12) 将忽略标志 match_not_bol 和 match_not_bow


推荐阅读