Bug 8714 - gcc bug: complaint on %c for strftime
Summary: gcc bug: complaint on %c for strftime
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2002-11-26 04:26 UTC by andries.brouwer
Modified: 2003-11-08 22:59 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-08-16 03:56:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description andries.brouwer 2002-11-26 04:26:05 UTC
 Various versions of gcc such as gcc 3.2 complain
 about strftime(,,"%c",) with the reaction
 
 warning: `%c' yields only last 2 digits of year in some locales
 
 This is a bug.
 
 %c is described as: the preferred date and time representation
 for the current locale. How can you give an error message for
 that? What is the programmer to do? Choose a non-preferred
 representation?
 
 The docs for Wall say:
        -Wall  All  of the above `-W' options combined.  These are
               all the options which pertain to usage that we rec­
               ommend  avoiding  and  that  we  believe is easy to
               avoid, even in conjunction with macros.
 so %c should be easy to avoid. I have no idea how.
 
 But the warning is easy to avoid using silliness like
 
 /*
  * Stop extremely silly gcc complaint on %c:
  *  warning: `%c' yields only last 2 digits of year in some locales
  */
 static void
 my_strftime(char *buf, size_t len, const char *fmt, const struct tm *tm) {
         strftime(buf, len, fmt, tm);
 }
 
 [this is what I do now in util-linux, but I can hardly imagine
 that this is what you hoped to achieve].
 
 Andries

Release:
unknown
Comment 1 Wolfgang Bangerth 2002-12-04 14:10:20 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: Could you please post a self-contained testcase that shows
    the report?
    
    Thanks
      Wolfgang
Comment 2 Wolfgang Bangerth 2002-12-04 17:54:42 UTC
State-Changed-From-To: feedback->analyzed
State-Changed-Why: Testcase received. The warning still appears with 3.3CVS.
    I think it was introduced to warn about possible Y2K problems.
    Being a C++ programmer, I think I have no opinion about
    whether this warning is a good thing or not.
Comment 3 andries.brouwer 2002-12-05 01:20:26 UTC
From: Andries.Brouwer@cwi.nl
To: Andries.Brouwer@cwi.nl, bangerth@dealii.org, gcc-bugs@gcc.gnu.org,
        gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org
Cc:  
Subject: Re: c/8714: gcc bug: complaint on %c for strftime
Date: Thu, 5 Dec 2002 01:20:26 +0100 (MET)

 > Could you please post a self-contained testcase
 
 #include <time.h>
 int main() { strftime((char *)0,0,"%c",(struct tm *)0); return 0; }
 
 
 % gcc -Wall strftime.c
 strftime.c: In function `main':
 strftime.c:2: warning: `%c' yields only last 2 digits of year in some locales
 
Comment 4 GCC Commits 2003-11-08 22:42:04 UTC
Subject: Bug 8714

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2003-11-08 22:42:00

Modified files:
	gcc            : ChangeLog c-format.c 
	gcc/doc        : invoke.texi 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg/format: c90-strftime-1.c c90-strftime-2.c 
	                             c99-strftime-1.c ext-3.c no-y2k-1.c 

Log message:
	PR c/3190
	PR c/8714
	* c-format.c (set_Wformat): Do not enable -Wformat-y2k by default.
	* invoke.texi: Update.
	
	testsuite:
	PR c/3190
	PR c/8714
	* gcc.dg/format/c90-strftime-1.c, gcc.dg/format/c90-strftime-2.c,
	gcc.dg/format/c99-strftime-1.c, gcc.dg/format/ext3.c,
	gcc.dg/format/no-y2k-1.c: Update.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1705&r2=2.1706
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-format.c.diff?cvsroot=gcc&r1=1.49&r2=1.50
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/invoke.texi.diff?cvsroot=gcc&r1=1.357&r2=1.358
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3176&r2=1.3177
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/format/c90-strftime-1.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/format/c90-strftime-2.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/format/c99-strftime-1.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/format/ext-3.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/format/no-y2k-1.c.diff?cvsroot=gcc&r1=1.2&r2=1.3

Comment 5 Andrew Pinski 2003-11-08 22:59:56 UTC
Fixed in 3.4 by removing -Wformat-2K from -Wformat.