此代码针对不同版本的 gcc 编译器显示不同的输出
#include "date.h"
#include <iostream>
#include <chrono>
#include <string>
#include <set>
#include <ranges>
#include <algorithm>
using namespace date;
using namespace std;
using namespace std::chrono;
using time_point_t = std::chrono::sys_time<std::chrono::microseconds>;
time_point_t parse_tp(std::string s) {
time_point_t tp;
std::istringstream in(s);
in >> parse("%Y%m%d-%T", tp);
return tp;
}
int
main()
{
auto tp = parse_tp("20240304-13:00:00.002");
std::set<time_point_t> s = {tp, tp + std::chrono::seconds(1)};
std::cout << *std::ranges::lower_bound(s, tp + std::chrono::seconds(1));
}
是什么导致输出不同?
这是一个错误吗?
gcc-13版本正在调用
date::parse
,gcc-trunk版本正在调用std::chrono::parse
。这些应该做同样的事情,但是是独立的实现。
昨天我提交了 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114244,该文件属于该区域,但可能会也可能不会影响这个特定示例。