Chrono:使用 gcc 的同一程序的不同输出

问题描述 投票:0回答:1

此代码针对不同版本的 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));
}

海湾合作委员会13

gcc 主干

是什么导致输出不同?

这是一个错误吗?

gcc c++20 c++-chrono
1个回答
1
投票

gcc-13版本正在调用

date::parse
,gcc-trunk版本正在调用
std::chrono::parse
。这些应该做同样的事情,但是是独立的实现。

昨天我提交了 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114244,该文件属于该区域,但可能会也可能不会影响这个特定示例。

© www.soinside.com 2019 - 2024. All rights reserved.