Home Dashboard Directory Help
Search

time_put does not produce output when instantiated with wchar_t by Barfy


Status: 

Closed
 as Fixed Help for as Fixed


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

Description

Run the following code:

#include "stdafx.h"
#define _SCL_SECURE_NO_WARNINGS 1

#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;
    localtime_s(&tm,&now);

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

    assert(stop!=buffer);
}

int _tmain(int argc, _TCHAR* argv[])
{
    test("%y%m%d");
    test(L"%y%m%d");

    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.
Details
Sign in to post a comment.
Posted by Microsoft on 12/17/2012 at 5:22 PM
Hi,

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
stl@microsoft.com
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.