【问题标题】:C++11 cregex_iterator valgrind errorsC++11 cregex_iterator valgrind 错误
【发布时间】:2018-07-28 22:52:55
【问题描述】:

我用gcc 6.3.0('g++ -std=c++11')编译了如下小程序:

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

int main()
{
    const char *cstr = "abc def.ghi";
    regex r(R"(abc|\w+\.ghi)");
    for (cregex_iterator it(cstr, cstr + strlen(cstr), r); it != cregex_iterator{}; it++)
    {
        cout << (*it).str() << endl;
    }
}

程序输出没问题。但是,valgrind 报告错误:

条件跳转或移动取决于未初始化的值

在 0x10DF98:std::__cxx11::regex_iterator >::operator==(std::__cxx11::regex_iterator > const&) const(在 a.out 中)

按 0x10D796:std::__cxx11::regex_iterator >::operator!=(std::__cxx11::regex_iterator > const&) const(在 a.out 中)

by 0x10C75C: main (in a.out)

有人知道这里出了什么问题吗?

【问题讨论】:

  • 似乎适用于 C++14 ideone.com/bj8w4C
  • 您应该添加确切的命令来编译和链接程序。
  • @WiktorStribiżew sregex_iterator 不会导致 gcc 6.3.0 中的 valgrind 错误,但是我想使用 cregex_iterator。我尝试使用 gcc 7.3.0 并且有效。 g++ -std=c++11 main.cpp valgrind ./a.out abc def.ghi ERROR SUMMARY: 0 errors from 0 contexts

标签: regex c++11 gcc


【解决方案1】:

使用 GCC 7 编译时,使用 cregex_iterator 类的代码 sn-p 运行时不会出现 valgrind 错误。 感谢您对此主题表现出兴趣。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多