【发布时间】:2015-06-27 08:27:46
【问题描述】:
#include <iostream>
#include <regex>
#include <string>
int main()
{
std::string example{" <match1> <match2> <match3>"};
std::regex re{"<([^>]+)>"};
std::regex_token_iterator<std::string::iterator> it{example.begin(), example.end(), re, 1};
decltype(it) end{};
while (it != end) std::cout << *it++ << std::endl;
return 0;
}
两个站点都使用 GCC 4.9.2。我不知道 ideone 使用什么编译参数,但在 Coliru 中并没有什么不寻常的地方。
Coliru 没有给我match1 结果:
科利鲁
# g++ -v 2>&1 | grep version; \
# g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
gcc version 4.9.2 (GCC)
match2
match3
ideone(顺便说一句,Coliru's clang 3.5.0 using libc++)
match1
match2
match3
我的代码有未定义的行为吗?是什么原因造成的?
【问题讨论】:
-
感谢“Veritas”在聊天中提出这个问题。
-
一个明显的可能性:即使他们使用相同的编译器,他们使用不同的标准库。
-
GCC 通常不附带特定的 libstdc++ 版本吗?如果 libstdc++ 版本在 GCC 4.9.2 安装之间存在差异(通常),难道不会出现问题吗?
-
Hmmmm...将
++移出*it++可以在Coliru 中修复它。是否存在在regex_token_iterator上的后修复++返回错误对象的错误?也就是说,它似乎在 增量之后返回对象。