Opened 7 years ago
Closed 7 years ago
#11330 closed Bugs (fixed)
boost::chrono::duration default constructor doesn't initialize rep_
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | Boost 1.60.0 | Component: | chrono |
Version: | Boost 1.58.0 | Severity: | Regression |
Keywords: | Cc: |
Description
According to the documentation:
constexpr duration(); Effects: Constructs an object of type duration from duration_values<rep>::zero().
The implementation is:
#if defined BOOST_NO_CXX11_DEFAULTED_FUNCTIONS BOOST_FORCEINLINE BOOST_CONSTEXPR duration() : rep_(duration_values<rep>::zero()) { } #else BOOST_CONSTEXPR duration() BOOST_NOEXCEPT {}; #endif
So in one side is does initialise to zero, not in the other side. This is a breaking change triggering tons of MSan issues in my application (and certainly bugs in real applications). Setting rep_ to zero() as it is done above fixes the issue for me.
Change History (8)
comment:1 by , 7 years ago
Status: | new → assigned |
---|
comment:2 by , 7 years ago
I guess that's fair as long as it is documented as a breaking change and the documentation doesn't claim it is initialized.
I was thinking of possibly migrating the code to std::chrono so I'll have to make sure everything is properly initialized anyway. In the mean time, I guess having a local patch to initialize it to zero so I can migrate the rest of my code to 1.58.0 is fine.
comment:3 by , 7 years ago
So you agree for been forced to define BOOST_CHRONO_DURATION_DEFAULTS_TO_ZERO?
comment:6 by , 7 years ago
Milestone: | To Be Determined → Boost 1.60.0 |
---|
comment:7 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Hi,
you are right that there is an inconsistency I need to document.
The correct behavior is, following the standard, to don't initialize it. I received a request to be able to initialize it a zero.
I'm really sorry, but I would not initialize it in c++11. I could add a compiler flag to force the initialization.