Modify

Opened 2 years ago

Closed 2 years ago

#11330 closed Bugs (fixed)

boost::chrono::duration default constructor doesn't initialize rep_

Reported by: florent.castelli@… 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.

Attachments (0)

Change History (8)

comment:1 Changed 2 years ago by viboes

Status: newassigned

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.

#if  defined   BOOST_NO_CXX11_DEFAULTED_FUNCTIONS || \
     defined   BOOST_CHRONO_DURATION_DEFAULTS_TO_ZERO
        BOOST_FORCEINLINE BOOST_CONSTEXPR
        duration() : rep_(duration_values<rep>::zero()) { }
#else
        BOOST_CONSTEXPR duration() BOOST_NOEXCEPT {};
#endif

comment:2 Changed 2 years ago by florent.castelli@…

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 Changed 2 years ago by viboes

So you agree for been forced to define BOOST_CHRONO_DURATION_DEFAULTS_TO_ZERO?

comment:4 Changed 2 years ago by florent.castelli@…

Yes

comment:4 Changed 2 years ago by florent.castelli@…

Yes

comment:5 Changed 2 years ago by viboes

I was on vacation. I will do it asap.

comment:7 Changed 2 years ago by viboes

Resolution: fixed
Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain viboes.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.