Bug 9780

Summary: issues with time_get, time_put not being tied to correct _punct facet.
Product: gcc Reporter: Benjamin Kosnik <bkoz>
Component: libstdc++Assignee: Not yet assigned to anyone <unassigned>
Status: SUSPENDED ---    
Severity: normal CC: gcc-bugs, webrown.cpp
Priority: P3    
Version: 3.4.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2005-09-26 00:37:58
Bug Depends on:    
Bug Blocks: 86976    

Description Benjamin Kosnik 2003-02-20 18:36:00 UTC
See:
http://gcc.gnu.org/ml/libstdc++/2003-01/msg00363.html

And followups.

Seems like an issue with __timepunct not really being used  correctly with time_get and time_put facets. 

When fixing this, please double check the other facets for this behavior as well. Likely candidates are money_put, money_get, num_get, num_put, etc: anything that uses a *_punct facet for data collection.

Release:
gcc-3.2, gcc-3.3, gcc-3.4 not applicable to releases before gcc-3.2

Environment:
x86/linux, gnu locale model

How-To-Repeat:
#include <iostream>
#include <locale>

int main ()
{
     const std::locale loc ("de_DE");

     const std::time_put<char> &tpc =
         std::use_facet<std::time_put<char> >(loc);

     std::tm t = std::tm ();

     for (t.tm_wday = 0; t.tm_wday != 7; ++t.tm_wday)
         tpc.put (std::cout.rdbuf (), std::cout, ' ', &t, 'A') = '\n';
}


or



#include <iostream>
#include <locale>

int main (int argc, const char *argv[])
{
     const std::locale l1 (argc > 1 ? argv [1] : "");
     const std::locale l2 (argc > 2 ? argv [2] : "");

     const std::locale l1_l2 =
         std::locale (std::locale (std::locale::classic (),
                                   &std::use_facet<std::time_get<char> 
 >(l1)),
                      &std::use_facet<std::time_put<char> >(l2));

     const std::time_get<char> &tg =
         std::use_facet<std::time_get<char> >(l1_l2);

     const std::time_put<char> &tp =
         std::use_facet<std::time_put<char> >(l1_l2);

     std::tm t = std::tm ();

     std::ios::iostate err = std::ios::goodbit;

     // benign but unnecessary
     // std::cin.imbue (l1_l2);
     // std::cout.imbue (l1_l2);

     tg.get_weekday (std::cin.rdbuf (), std::istreambuf_iterator<char>(),
                     std::cin, err, &t);

     if (err & std::ios::failbit)
         return 1;

     tp.put (std::cout.rdbuf (), std::cout, ' ', &t, 'A') = '\n';
}
Comment 1 Benjamin Kosnik 2003-03-11 15:05:45 UTC
Responsible-Changed-From-To: unassigned->bkoz
Responsible-Changed-Why: Mine.
Comment 2 Benjamin Kosnik 2003-03-11 15:05:45 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: No longer super-concerned about this, although it is a bug. 
    
    It doesn't apply to money or numeric facets, because they have their own *punct facets, and this kind of code would not be attempted (instead, the proper *punct facet would also be used).
    
    I consider the lack of timepunct in the standard a bug. 
    
    However, things should still work, even with the current bogus design of time facets. I'll work on a hack to fix this.
    
    -benjamin
Comment 3 Andrew Pinski 2003-12-05 03:16:06 UTC
Any news on this.
Comment 4 Benjamin Kosnik 2003-12-05 07:00:13 UTC
Subject: Re:  issues with time_get, time_put not being
 tied to correct _punct facet.

>Any news on this.

this is a fatal flaw in the standard. It can be worked around, much like
money_get and money_put are able to be used: by also imbuing the
moneypunct (and here, __timepunct) facet.

You can suspend this if you'd like.

-benjamin
Comment 5 Andrew Pinski 2003-12-19 09:58:03 UTC
Suspending based on Benjamin's comments.
Comment 6 Andrew Pinski 2023-05-16 19:41:59 UTC
Reassining since Benjamin has not been active in GCC development for a few years now.