What do you expect?
Even if it is valid, it would not be functional.
As was pointed out, constexpr functions are not necessarily evaluated in any order.
So it makes no sense to measure a time duration.
So even if now() changes its value, the second now() could be evaluated before the first.
Or possibly the compiler could cache the value from a previous compilation run and use the cached value for either or both.
As now() is not constexpr at the current standard, the code could be made valid or not.
It probably would only make sense, if now() always returns the same value for each translation unit. Any other result would tempt to make time measurements.
-----Ursprüngliche Nachricht-----
Von: Tiago Freire via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mo 10.03.2025 00:02
Betreff: Re: [std-proposals] constexpr support for std::chrono::system_clock
An: std-proposals@lists.isocpp.org;
CC: Tiago Freire <tmiguelf@hotmail.com>;
I thought that I needed to make a decision before presenting 1 of 2 types of gadgets that broke things in different ways, but after thinking about it.extern uint32_t g0;constexpr auto g1 = now();constexpr uint32_t foo(uint32_t var){if constexpr ( now() - g1 > nanoseconds(3) ){return var + 1;}else{return var - 1;}}uint32_t const g2 = foo(g0);Is this valid?-- Std-Proposals mailing list Std-Proposals@lists.isocpp.org https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals