我认为以下程序应该抱怨它不能编译正则表达式,或者将其视为合法并编译它(我没有标准,所以我不能确定表达式是否严格合法;当然合理的解释是可能的)。无论如何,发生的事情g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
是,在运行时,它会严重崩溃
*** Error in `./a.out': free(): invalid next size (fast): 0x08b51248 ***
在图书馆的内脏。
问题是:
a)这是错误,对吗?我假设(也许是错误的)标准没有说 std::regex 如果它不喜欢语法会崩溃。(msvc 吃得很好,fwiw)
b)如果它是一个错误,是否有一些简单的方法可以查看它是否已被报告(我第一次在 gnu-land 错误系统周围探查是令人生畏的)?
#include <iostream>
#include <regex>
int main(void)
{
const char* Pattern = "^(%%)|";
std::regex Machine;
try {
Machine = Pattern;
}
catch(std::regex_error e)
{
std::cerr << "regex could not compile pattern: "
<< Pattern << "\n"
<< e.what() << std::endl;
throw;
}
return 0;
}