Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


3
0
Sign in
to vote
Type: Bug
ID: 752794
Opened: 7/7/2012 6:32:29 PM
Access Restriction: Public
0
Workaround(s)
view
2
User(s) can reproduce this bug

Description

//Example Code from C++ Standard: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm
// 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[]) {
f(microseconds(3));
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
}
Details
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
Hi,

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
stl@microsoft.com
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 :
http://stackoverflow.com/questions/12231843/a-strange-error-in-chrono-code-c2440-function-style-cast-cannot-convert
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(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
UploadSummary-120708013228.xml (restricted) 7/7/2012 -
VsInfo.xml (restricted) 7/7/2012 -
SqmExtensionsLogs.zip (restricted) 7/7/2012 -
DxDiagOutput.txt (restricted) 7/7/2012 -
SolutionFingerprint.6772.html (restricted) 7/7/2012 -