[Bug c++/67762] [C++1z] 'not a constant expression" errors only with -fsanitize=undefined
curdeius at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Nov 10 13:03:22 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67762
--- Comment #8 from Curdeius Curdeius <curdeius at gmail dot com> ---
A different (rather small) reproduce.
https://godbolt.org/z/bz9sTd34o
It fails with all the versions of gcc from at least 7 (the above code needs
`auto` in template non-type parameter) to trunk from 2021-11-10.
Hope it helps!
```
#include <date/date.h>
#include <chrono>
#include <functional>
namespace detail {
static inline void validate(date::weekday v) noexcept {
(void)v;
assert(v.ok());
}
template <typename Duration, auto InitValue, auto GetValue = nullptr>
struct date_interval {
using duration_type = Duration;
duration_type begin{InitValue};
[[nodiscard]] constexpr auto begin_value() const noexcept {
if constexpr (GetValue != nullptr) {
return std::invoke(GetValue, begin);
} else {
return begin;
}
}
};
} // namespace detail
using days_interval = detail::date_interval<date::weekday, /*date::Sunday*/ 7,
&date::weekday::c_encoding>;
int main() {
days_interval days;
return (int)days.begin_value();
}
```
More information about the Gcc-bugs
mailing list