From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16986 invoked by alias); 10 May 2014 16:47:18 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 16942 invoked by uid 48); 10 May 2014 16:47:13 -0000 From: "hugh at mimosa dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/39438] Can't compile a wrapper around strftime with -Werror=format-nonliteral Date: Sat, 10 May 2014 16:47:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.3.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hugh at mimosa dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-05/txt/msg00913.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39438 D. Hugh Redelmeier changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hugh at mimosa dot com --- Comment #4 from D. Hugh Redelmeier --- I have this problem too. I'm writing a wrapper for strftime. I get a warning on the actual strftime call. warning: format not a string literal, format string not checked [-Wformat-nonliteral] strftime(buf, buflen, fmt, t); Surely GCC should not that for "fmt" argument has been checked to be a valid strftime format at the points where prettynow gets called. So there is no need to whine that it is unchecked. static void prettynow(char *buf, size_t buflen, const char *fmt) __attribute__ ((format (__strftime__, 3, 0))); static void prettynow(char *buf, size_t buflen, const char *fmt) { time_t n = time(0); struct tm tm1; struct tm *t = localtime_r(&n, &tm1); strftime(buf, buflen, fmt, t); } I'm using gcc-4.8.2-7.fc20.x86_64 on Fedora 20. I managed to suppress the warning with a very ugly cast: ((size_t (*)(char *, size_t, const char *, const struct tm *))strftime)(buf, buflen, fmt, t);