Home Dashboard Directory Help

time_put does not produce output when instantiated with wchar_t by Barfy


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 766065
Opened: 10/4/2012 4:32:11 AM
Access Restriction: Public
User(s) can reproduce this bug


Run the following code:

#include "stdafx.h"

#include <tchar.h>
#include <locale>
#include <time.h>
#include <chrono>
#include <sstream>

#include <cassert>

template<class Char,size_t N>
void test(const Char (&fmt)[N])
    Char buffer[256];
    std::locale loc;
    std::basic_stringstream<Char> stub;

    auto now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

    std::tm tm;

    auto stop=std::use_facet<std::time_put<Char,Char *>>(loc).put(buffer,stub,(Char) ' ',&tm,std::begin(fmt),std::end(fmt)-1);


int _tmain(int argc, _TCHAR* argv[])

    return 0;

It uses time_put facet to convert std::tm to string. While the overload that uses "char" succeeds, overload that uses "wchar_t" produces empty buffer, assert fires.

The same code in Visual Studio 2010 works correctly.
Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:32 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 12/17/2012 at 5:22 PM

Thanks for reporting this bug. We've fixed it, and the fix will be available in the next release of our C++ Standard Library implementation. The implementations for time_put<char> and time_put<wchar_t> had diverged, and the latter wasn't properly returning an advanced iterator. (time_put<unsigned short> was also affected and fixed, for users compiling with /Zc:wchar_t-.)

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 Barfy on 10/5/2012 at 5:12 AM
Slightly modified the example - while the bug is actually there, the example was a bit incorrect. Now it correctly specified begin/end for format string, and asserts if returned iterator is the same as beginning iterator.
Posted by Microsoft on 10/4/2012 at 7:51 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 10/4/2012 at 4:51 AM
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.