【问题标题】:Wrong implementation for regex_constants in clang?clang 中 regex_constants 的错误实现?
【发布时间】:2019-06-08 10:47:41
【问题描述】:

standard中指定:

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++11 clang++ c++-standard-library


    【解决方案1】:

    您似乎在 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 是一个有效的迭代器位置。当设置此标志时,正则表达式将忽略标志 match_not_bol 和 match_not_bow 算法(30.11)和迭代器(30.12)

    【讨论】:

    • 你会在 bugs.llvm.org 上记录这个吗?
    • 我添加了报告链接,让 OP 获得信任,因为他/她发现了它。
    • 据我了解,match_prev_avail 的行为与match_not_bol 相同,对吧?或者更准确地说,match_prev_avail 等价于match_not_bol | match_not_bow?
    • @skeller 我已经用 ID 42199 报告了它。顺便说一句,“OP”是什么意思? ^_^
    猜你喜欢
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 2011-04-01
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多