https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102876

--- Comment #3 from Mathias Stearn <redbeard0531 at gmail dot com> ---
> Why not just make the function constexpr though?

That isn't always possible. Sometimes the initializer may call a third-party
function that is inline, but not yet marked constexpr (it may need to support
older language versions where it couldn't be constexpr). Other times the
initializer may call a function that is out of line (so can't be constexpr at
all), but defined in the same TU. MSVC and clang handle this somewhat more
realistic example nicely, gcc doesn't: https://godbolt.org/z/jYKx8359T

The original example using chrono was just something that when reading I
thought "any optimizer worth its salt should be able to do this even without
explicit constexpr annotation". I was disappointed to learn that gcc couldn't,
so I filed a bug in the hope that it can be improved.

Reply via email to