zserio
zserio copied to clipboard
All generated c++ const literals should be constexpr
zs file
const string StringViewShouldBeConstexpr = "ShouldBeConstexpr";
const float64 Float64ShouldBeConstexpr = 0;
...
generated c++ file
/*now*/ const ::zserio::StringView StringViewShouldBeConstexpr = ::zserio::makeStringView("ShouldBeConstexpr");
/*new*/ constexpr ::zserio::StringView StringViewShouldBeConstexpr = ::zserio::makeStringView("ShouldBeConstexpr");
/*now*/ const double Float64ShouldBeConstexpr = 0;
/*new*/ constexpr double Float64ShouldBeConstexpr = 0;
https://github.com/ndsev/zserio/blob/master/test/language/literals/cpp/LiteralsTest.cpp It should be possible to test all literals with static_assert()
Yes, constexpr will be better. Thanks to pointing this out!
We will have to check all consts in the generated code and in the C++ runtime library because of that. It would be good to have constexpr wherever it is possible.
Thanks. It works like a charm.