这是谁的错误 - clang 还是 gcc?
Whose bug is this - clang or gcc?
#include <regex>
#include <string>
#include <iostream>
using namespace std;
bool IsMatched()
{
string str = R"(Liy_0-3863)";
string re = R"([:\-_a-zA-Z\d]+)";
auto flags = std::regex_constants::ECMAScript;
return std::regex_match(str.data(),
std::regex(re.data(), re.size(), flags));
}
int main()
{
cout << boolalpha << IsMatched();
}
- clang 4.0 输出
true
;
- gcc 6.2 输出
false
.
这是谁的 bug - clang 还是 gcc?
g++(或者更确切地说是 stdlibc++)在错误中。
根据 ECMAScript 规范,转义减号字符应按字面意义处理字符 class。 libstdc++ 无法做到这一点。可以在一个更简单的例子中看到
string: a-b
regex: [a\-b]+
gcc 说没有匹配项,各种正则表达式测试人员说有。
#include <regex>
#include <string>
#include <iostream>
using namespace std;
bool IsMatched()
{
string str = R"(Liy_0-3863)";
string re = R"([:\-_a-zA-Z\d]+)";
auto flags = std::regex_constants::ECMAScript;
return std::regex_match(str.data(),
std::regex(re.data(), re.size(), flags));
}
int main()
{
cout << boolalpha << IsMatched();
}
- clang 4.0 输出
true
; - gcc 6.2 输出
false
.
这是谁的 bug - clang 还是 gcc?
g++(或者更确切地说是 stdlibc++)在错误中。
根据 ECMAScript 规范,转义减号字符应按字面意义处理字符 class。 libstdc++ 无法做到这一点。可以在一个更简单的例子中看到
string: a-b
regex: [a\-b]+
gcc 说没有匹配项,各种正则表达式测试人员说有。