【发布时间】:2014-11-11 14:18:20
【问题描述】:
我从 std::regex_search 得到各种错误结果,似乎取决于程序中的其他代码:
#include <regex>
#include <iostream>
int main(){
std::smatch res;
std::regex_search(std::string("fooquxbarquack"),res,std::regex("foo(?=qux)(.*)ar"));
std::cout<<res[0]<<std::endl;
std::regex_search(std::string("foofofowoof"),res,std::regex("(o.){4}"));
std::cout<<res[0]<<std::endl;
return 0;
}
输出(格式化为 c 字符串):
fooquxba0\n
ofofow\xB0\x00\n
如果我反转测试,输出变为:
ofofow\xD0\x00\n
fooquxbar\n
在代码的其他安排下,它有时会产生预期的输出(fooquxbar 和 ofofowoo)。
gcc 版本:
$ ../bin/gcc -v
Using built-in specs.
COLLECT_GCC=../bin/gcc
COLLECT_LTO_WRAPPER=/compilers/gcc_r/4.9.1rh62/libexec/gcc/x86_64-unknown-linux-gnu/4.9.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /free/tmp/gccwork/gcc-4.9.1//configure --prefix=/compilers/gcc_r/4.9.1rh62/
Thread model: posix
gcc version 4.9.1 (GCC)
【问题讨论】: