This code displays different output for different versions of gcc compiler
#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));
}
What makes the output different?
Is it a bug?
The gcc-13 version is calling date::parse
, and the gcc-trunk version is calling std::chrono::parse
. These are supposed to do the same thing, but are independent implementations.
Yesterday I filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114244 which is in this area, but may or may not impact this specific example.
See the comment below by Ted Lyngmo for a good explanation of this behavior.