gpt4 book ai didi

Fedora 19 上的 C++11/g++4.8 regex_match 段错误

转载 作者:太空狗 更新时间:2023-10-29 23:17:24 24 4
gpt4 key购买 nike

#include <regex>
#include <iostream>

using namespace std;

void out(bool b)
{
cout<< ( b ? "found" : "not found" )<<endl;
}

int main()
{

// find XML/HTML-tagged value(tags before and after the value must match):
//regex reg2("<(.*)>.*</\\1>");

regex reg2(R"(<(.*)>.*</\1>)");
bool found = regex_match("<tag>value</tag>",
reg2);
out(found);
}

$ g++ -g -std=c++11 regex1.cpp

$ ./a.out

Segmentation fault (core dumped)


$ gdb a.out core.12473

GNU gdb (GDB) Fedora (7.6-30.fc19)
Reading symbols from /home/neo/code/regex/a.out...done.
[New LWP 12473]
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 0x0804a352 in std::__detail::_StateSeq::_M_append (this=0xbf948a30, __rhs=...)
at /usr/include/c++/4.8.1/bits/regex_nfa.tcc:157
157 _M_nfa[_M_end2]._M_next = __rhs._M_start;
Missing separate debuginfos, use: debuginfo-install glibc-2.17-11.fc19.i686 libgcc-4.8.1-1.fc19.i686 libstdc++-4.8.1-1.fc19.i686
(gdb) bt
#0 0x0804a352 in std::__detail::_StateSeq::_M_append (this=0xbf948a30, __rhs=...)
at /usr/include/c++/4.8.1/bits/regex_nfa.tcc:157
#1 0x0804ea33 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:779
#2 0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#3 0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#4 0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#5 0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#6 0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#7 0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#8 0x0804dc21 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_disjunction (
this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:758
#9 0x0804ce38 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_Compiler (this=0xbf948c68,
__b=@0xbf948d34: 0x80538ff "<(.*)>.*</\\1>", __e=@0xbf948d0c: 0x805390c "", __traits=..., __flags=16)
at /usr/include/c++/4.8.1/bits/regex_compiler.h:729
#10 0x0804bb51 in std::__detail::__compile<char const*, std::regex_traits<char> > (
__b=@0xbf948d34: 0x80538ff "<(.*)>.*</\\1>", __e=@0xbf948d0c: 0x805390c "", __t=..., __f=16)
at /usr/include/c++/4.8.1/bits/regex_compiler.h:1105
#11 0x0804b0bb in std::basic_regex<char, std::regex_traits<char> >::basic_regex (this=0xbf948d4c,
__p=0x80538ff "<(.*)>.*</\\1>", __f=16) at /usr/include/c++/4.8.1/bits/regex.h:388
#12 0x08049847 in main () at regex1.cpp:17

最佳答案

直到 4.9(撰写本文时的当前主干),GCC 才完全支持 C++11 正则表达式。详情请查看http://gcc.gnu.org/gcc-4.9/changes.html ,在“运行时库 (libstdc++)”部分下。

关于Fedora 19 上的 C++11/g++4.8 regex_match 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18247165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com