This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.

### 974. `duration<double>` should not implicitly convert to `duration<int>`

Section: 29.5.2 [time.duration.cons] Status: C++11 Submitter: Howard Hinnant Opened: 2009-01-21 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [time.duration.cons].

View all issues with C++11 status.

Discussion:

The following code should not compile because it involves implicit truncation errors (against the design philosophy of the `duration` library).

>     duration<double> d(3.5);
>     duration<int> i = d;  // implicit truncation, should not compile

This intent was codified in the example implementation which drove this proposal but I failed to accurately translate the code into the specification in this regard.

[ Batavia (2009-05): ]

> We agree with the proposed resolution.

> Move to Tentatively Ready.

[ 2009-07 Frankfurt ]

> Moved from Tentatively Ready to Open only because the wording needs to be improved for `enable_if` type constraining, possibly following Robert's formula.

[ 2009-08-01 Howard adds: ]

> Addressed by 1177.

[ 2009-10 Santa Cruz: ]

> Not completely addressed by 1177. Move to Ready.

Proposed resolution:

Change 29.5.2 [time.duration.cons], p4:

>     template <class Rep2, class Period2>
>       duration(const duration<Rep2, Period2>& d);

> > -4- Requires: `treat_as_floating_point<rep>::value` shall be `true` or both `ratio_divide<Period2, period>::type::den` shall be 1 and `treat_as_floating_point<Rep2>::value` shall be `false`. Diagnostic required. [Note: This requirement prevents implicit truncation error when converting between integral-based `duration` types. Such a construction could easily lead to confusion about the value of the `duration`. — end note]