考虑带有签名 std::regex_match(
std::string const&, std::smatch& match, std::regex const& re )
的 C++11 函数,第一个参数的生命周期有什么限制?我没有发现任何限制,但是当我执行以下程序(使用 VC++ 2010 编译,启用了迭代器调试):
int
main()
{
std::string a("aaa");
std::string c("ccc");
std::regex re("aaa(.*)ccc");
std::smatch m;
if (std::regex_match(a + "xyz" + c, m, re)) {
std::cout << m[0] << std::endl;
std::cout << m[1] << std::endl;
}
return 0;
}
毫无疑问,IT出现了崩溃,原因是m
中的sub_match
仅保留了字符串的迭代器而非副本。在标准中,我找不到任何禁止我的代码的内容。
顺便说一下:即使在基于std::regex
的boost::regex
中也不能正常工作。(当然,Boost也没有文档说明寿命的限制。)
最后,我想问的是:我应该向标准组织提交DR还是向Microsoft提交错误报告?