Bug 8887

Summary: locale
Product: gcc Reporter: dmitry_belous
Component: libstdc++Assignee: Paolo Carlini <paolo.carlini>
Status: RESOLVED FIXED    
Severity: normal CC: bkoz, gcc-bugs, pcarlini
Priority: P3    
Version: 3.2   
Target Milestone: ---   
Host: i686-pc-cygwin Target: i686-pc-cygwin
Build: i686-pc-cygwin Known to work:
Known to fail: Last reconfirmed:

Description dmitry_belous 2002-12-10 00:56:00 UTC
Class time_get<> is not corresponding to time_put<>.
Source documentation
`22 - Localization library [lib.localization]',
section 22.2.5.1 (-1-) && 22.2.5.1.2 (-4-).
For example, running the following program tnum should
print like dates.

Release:
3.2 20020818 (prerelease)

Environment:
System: W2K
Architecture: i686
host: i686-pc-cygwin
build: i686-pc-cygwin
target: i686-pc-cygwin

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

int main()
{
	using namespace std;
	tm* lt = localtime(&time(0));
	try {
		const time_put<char>& tp = use_facet<time_put<char> >(locale());
		const time_get<char>& tg = use_facet<time_get<char> >(locale());
		ostringstream os;
		tp.put(os, os, os.fill(), lt, 'x');
		cout << os.str() << endl;
		istringstream is(os.str());
		istreambuf_iterator<char> end;
		ios_base::iostate err = ios_base::goodbit;
		tm x = {0};
		tg.get_date(is, end, is, err, &x);
		tp.put(cout, cout, cout.fill(), &x, 'x');
	} catch(...) {
		cerr << "error" << endl;
	}
}

g++ -ansi -v -o main.exe main.cpp -W -Wall -g
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.2/specs
Configured with: /netrel/src/gcc-3.2-1/configure --enable-languages=c,c++,f77,java --enable-libgcj --enable-threads=posix --with-system-zlib --enable-nls --without-included-gettext --enable-interpreter --disable-sjlj-exceptions --disable-version-specific-runtime-libs --enable-shared --build=i686-pc-linux --host=i686-pc-cygwin --target=i686-pc-cygwin --enable-haifa --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --includedir=/nonexistent/include --libexecdir=/usr/sbin
Thread model: posix
gcc version 3.2 20020818 (prerelease)
 /usr/lib/gcc-lib/i686-pc-cygwin/3.2/cc1plus.exe -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=0 -D__GXX_ABI_VERSION=102 -D_X86_=1 -Asystem=winnt -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ -D__tune_pentium2__ -D__tune_pentium3__ -D__stdcall=__attribute__((__stdcall__)) -D__fastcall=__attribute__((__fastcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -D__i386__ -D__i386 -D__CYGWIN32__ -D__CYGWIN__ -D__unix__ -D__unix -isystem /usr/lib/gcc-lib/i686-pc-cygwin/3.2/../../../../include/w32api -isystem /usr/local/lib/../../include/w32api main.cpp -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -D__STRICT_ANSI__ -trigraphs -$ -quiet -dumpbase main.cpp -ansi -g -W -Wall -ansi -version -o /tmp/ccdCW2C3.s
GNU CPP version 3.2 20020818 (prerelease) (cpplib) (80386, BSD syntax)
GNU C++ version 3.2 20020818 (prerelease) (i686-pc-cygwin)
	compiled by GNU C version 3.2 20020815 (prerelease).
ignoring nonexistent directory "/usr/i686-pc-cygwin/include"
ignoring duplicate directory "/usr/include/w32api"
#include "..." search starts here:
#include <...> search starts here:
 .
 /usr/include/libxml2
 /usr/include/w32api
 /usr/include/c++/3.2
 /usr/include/c++/3.2/i686-pc-cygwin
 /usr/include/c++/3.2/backward
 /usr/local/include
 /usr/lib/gcc-lib/i686-pc-cygwin/3.2/include
 /usr/include
End of search list.
main.cpp: In function `int main()':
main.cpp:8: non-lvalue in unary `&'
main.cpp:18: warning: missing initializer for member `tm::tm_min'
main.cpp:18: warning: missing initializer for member `tm::tm_hour'
main.cpp:18: warning: missing initializer for member `tm::tm_mday'
main.cpp:18: warning: missing initializer for member `tm::tm_mon'
main.cpp:18: warning: missing initializer for member `tm::tm_year'
main.cpp:18: warning: missing initializer for member `tm::tm_wday'
main.cpp:18: warning: missing initializer for member `tm::tm_yday'
main.cpp:18: warning: missing initializer for member `tm::tm_isdst'
Comment 1 Paolo Carlini 2002-12-10 15:45:41 UTC
Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-Why: Analyzed a bit.
Comment 2 Paolo Carlini 2002-12-10 15:45:41 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: What are you actually getting at run time?
    If, paying attention to the warning ;), I modify line #8
    of your testcase from
      tm* lt = localtime(&time(0));
    to something like
      time_t tt = time(0);
      tm* lt = localtime(&tt);
    The date is correctly printed twice on my i686-pc-linux-gnu
    box.
Comment 3 pcarlini 2002-12-11 00:52:26 UTC
From: Paolo Carlini <pcarlini@unitus.it>
To: dmitry_belous@ua.fm,  gcc-gnats@gcc.gnu.org,  gcc-prs@gcc.gnu.org, 
 gcc-bugs@gcc.gnu.org,  paolo@gcc.gnu.org
Cc:  
Subject: Re: libstdc++/8887: locale
Date: Wed, 11 Dec 2002 00:52:26 +0100

 Sorry: s/warning/error
 
 Paolo.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8887
 
Comment 4 Benjamin Kosnik 2002-12-11 09:01:55 UTC
State-Changed-From-To: feedback->analyzed
State-Changed-Why: He's on W2k, using cygwin, so you'll have to use the generic locale model.
    
    -benjamin
Comment 5 Paolo Carlini 2002-12-11 16:25:41 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed for 3.3 and 3.2.2 with:
    http://gcc.gnu.org/ml/gcc-patches/2002-12/msg00640.html
Comment 6 pcarlini 2002-12-11 19:22:42 UTC
From: Paolo Carlini <pcarlini@unitus.it>
To: dmitry_belous@ua.fm,  gcc-gnats@gcc.gnu.org,  gcc-prs@gcc.gnu.org, 
 gcc-bugs@gcc.gnu.org,  paolo@gcc.gnu.org
Cc: bkoz <bkoz@redhat.com>
Subject: Re: libstdc++/8887: locale
Date: Wed, 11 Dec 2002 19:22:42 +0100

 Yes, configuring --enable-clocale=generic, something
 wrong happens:
 
 paolo:~> a.out
 12/11/02
 12/11/00paolo:~>
 
 The dates are unexpectedly different!
 
 Investigating further...
 
 Ciao,
 Paolo.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8887
 
Comment 7 Paolo Carlini 2002-12-12 00:22:59 UTC
From: paolo@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: libstdc++/8887
Date: 12 Dec 2002 00:22:59 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	paolo@gcc.gnu.org	2002-12-11 16:22:59
 
 Modified files:
 	libstdc++-v3   : ChangeLog 
 	libstdc++-v3/config/locale/generic: time_members.cc 
 
 Log message:
 	2002-12-11  Paolo Carlini  <pcarlini@unitus.it>
 	
 	PR libstdc++/8887
 	* config/locale/generic/time_members.cc
 	(__timepunct<char>::_M_initialize_timepunct): Fix typos
 	in _M_date_format and _M_date_era_format string literals.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.1463&r2=1.1464
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/config/locale/generic/time_members.cc.diff?cvsroot=gcc&r1=1.5&r2=1.6
 

Comment 8 Paolo Carlini 2002-12-12 00:30:17 UTC
From: paolo@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: libstdc++/8887
Date: 12 Dec 2002 00:30:17 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	paolo@gcc.gnu.org	2002-12-11 16:30:17
 
 Modified files:
 	libstdc++-v3   : ChangeLog 
 	libstdc++-v3/config/locale/generic: time_members.cc 
 
 Log message:
 	2002-12-11  Paolo Carlini  <pcarlini@unitus.it>
 	
 	PR libstdc++/8887
 	* config/locale/generic/time_members.cc
 	(__timepunct<char>::_M_initialize_timepunct): Fix typos
 	in _M_date_format and _M_date_era_format string literals.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1057.2.159.2.66&r2=1.1057.2.159.2.67
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/config/locale/generic/time_members.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1.2.3.2.1&r2=1.1.2.3.2.2