Title
duration<double> should not implicitly convert to duration<int>
Status
c++11
Section
[time.duration.cons]
Submitter
Howard Hinnant

Created on 2009-01-21.00:00:00 last changed 161 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Change [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]

Date: 2010-10-21.18:28:33

[ 2009-10 Santa Cruz: ]

Not completely addressed by 1177. Move to Ready.

Date: 2009-08-01.00:00:00

[ 2009-08-01 Howard adds: ]

Addressed by 1177.

Date: 2010-10-21.18:28:33

[ 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.

Date: 2010-10-21.18:28:33

[ Batavia (2009-05): ]

We agree with the proposed resolution.

Move to Tentatively Ready.

Date: 2009-01-21.00:00:00

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.

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 18:28:33adminsetmessages: + msg4635
2010-10-21 18:28:33adminsetmessages: + msg4634
2010-10-21 18:28:33adminsetmessages: + msg4633
2010-10-21 18:28:33adminsetmessages: + msg4632
2010-10-21 18:28:33adminsetmessages: + msg4631
2009-01-21 00:00:00admincreate