std::chrono::duration_cast lacks double support - by CodeSF

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 752794 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 7/7/2012 6:32:29 PM
Access Restriction Public


//Example Code from C++ Standard:
// Compiles with XCode [LLVM 3.1] and GCC 4.7
// Fails with VC2012
#include <chrono>
using namespace std::chrono;
void f(nanoseconds d) { // d.count() == 3000 when passed microseconds(3)

int main(int argc, char * argv[]) {
 duration<double> s(1./3);  // 1/3 of a second

 //Call below fails to compile with Microsoft Visual C++ 2012 RC   04167-004-0009005-02951 
 //ERROR: ...\microsoft visual studio 11.0\vc\include\chrono(543): error C2440: '<function-style-cast>' : cannot convert from '_CR' to 'std::chrono::nanoseconds'
 f(duration_cast<nanoseconds>(s));  // round towards zero in conversion to nanoseconds
Sign in to post a comment.
Posted by Henrik Stenby Andresen on 3/5/2014 at 1:13 AM
Is this issue implemented in VS2012 update 4? I just encountered the error on my system and fixed it by correcting the parentheses.
Posted by Microsoft on 10/9/2012 at 4:37 PM

Thanks for reporting this bug. We've fixed it, and the fix will be available in the next update to our C++ Standard Library implementation.

The problem was indeed caused by a misplaced parenthesis. I've carefully verified that all of the parentheses are now correct, and I've added a regression test for good measure.

Note: Connect doesn't notify me about comments. If you have any further questions, please E-mail me.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
Posted by Hogknuckle on 10/4/2012 at 9:12 PM
I ran into this issue today too, it looks like there's a misplaced parenthesis in duration_cast on line 544 of <chrono>:

static_cast<_CR>(_Dur.count())) * static_cast<_CR>(_CF::num)));

should be:

static_cast<_CR>(_Dur.count()) * static_cast<_CR>(_CF::num))));
Posted by Thomas Petit on 9/2/2012 at 4:08 AM
Another user hit by the same (or a very similar) bug in this stack overflow question :
Posted by Microsoft on 7/8/2012 at 11:55 PM
Thank you for submitting feedback on Visual Studio 11 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Microsoft on 7/7/2012 at 6:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(