The documentation for the format function attribute says: "The compiler always (unless -ffreestanding is used) checks formats for the standard library functions ... whenever such warnings are requested". However, these implicit attributes appear to be disabled also by -fno-builtin (which is implied by -ffreestanding). At the very least, the docs and the actual behaviour should match; but I think the current behaviour is incorrect, as without -ffreestanding it is still a hosted implementation, so printf etc. should be assumed to be standard. Test case: compile this code with -Wformat and with/without -fno-builtin: int printf(const char* format, ...); void foo(void) { printf("%s"); }
The documentation changed: -Wformat Check calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specified, and that the conversions specified in the format string make sense. This includes standard functions, and others specified by format attributes (see Function Attributes), in the printf, scanf, strftime and strfmon (an X/Open extension, not in the C standard) families (or other target-specific families). The formats are checked against the format features supported by GNU libc version 2.2. These include all ISO C90 and C99 features, as well as features from the Single Unix Specification and some BSD and GNU extensions. Other library implementations may not support all these features; GCC does not support warning about features that go beyond a particular library's limitations. However, if -pedantic is used with -Wformat, warnings will be given about format features not in the selected standard version (but not for strfmon formats, since those are not in any version of the C standard). See Options Controlling C Dialect . Since -Wformat also checks for null format arguments for several functions, -Wformat also implies - Wnonnull. -Wformat is included in -Wall. For more control over some aspects of format checking, the options - Wformat-y2k, -Wno-format-extra-args, -Wno-format-zero-length, -Wformat-nonliteral, -Wformat- security, and -Wformat=2 are available, but are not included in -Wall.
The documentation you quote is from a different section of the manual; I don't think it really adds anything. IMHO this is not purely a documentation bug.
Found it and yes it is just a documenation error: <http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html> The problem is that -fno-builtin did not exist until later and then was added which is where the problem comes into play.
Subject: Re: New: -fno-builtin prevents automatic format checks for standard functions On Fri, 30 Jul 2004, timb at bluearc dot com wrote: > The documentation for the format function attribute says: "The compiler always > (unless -ffreestanding is used) checks formats for the standard library > functions ... whenever such warnings are requested". However, these implicit > attributes appear to be disabled also by -fno-builtin (which is implied by > -ffreestanding). This would be a result of the changes to unify all the built-in attribute handling under the auspices of built-in functions (rather than having some handled one way and some handled the other way). Thus, it is an intended change and a documentation bug; -fno-builtin now disables all the special handling of particular function names (except for that using the remaining routes to such special handling, special_function_p and cp/cfns.gperf). You can of course use attributes in the headers declaring the standard format functions to get these warnings even with -fno-builtin.
Subject: Bug 16833 CVSROOT: /cvs/gcc Module name: gcc Changes by: jsm28@gcc.gnu.org 2004-09-23 16:11:24 Modified files: gcc : ChangeLog gcc/doc : extend.texi invoke.texi Log message: PR c/16833 * doc/extend.texi, doc/invoke.texi: Document interaction of -fno-builtin with format checks. Note that built-in functions have effects beyond generating code that avoids calls to those functions. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5586&r2=2.5587 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/extend.texi.diff?cvsroot=gcc&r1=1.218&r2=1.219 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/invoke.texi.diff?cvsroot=gcc&r1=1.539&r2=1.540
Fixed for 4.0.0.