From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27772 invoked by alias); 14 Feb 2014 12:27:23 -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 27742 invoked by uid 48); 14 Feb 2014 12:27:19 -0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/60194] -Wformat should also warn when using %d (instead of %u) for unsigned arguments Date: Fri, 14 Feb 2014 12:27: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.9.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org 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: 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-02/txt/msg01312.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60194 --- Comment #1 from Tobias Burnus --- > And of course also the other way round, e.g. using "%lu" or "%lz" with an > argument which is (signed) "long". (Ignore '%lz' that should be '%zu'.) Thinking a bit more about it, -Wformat-unsigned (implied by -Wformat=2) is probably the best - and ignoring the signdness for %c / character. (Currently, the code has the following. However, the example of comment 0 doesn't trigger even with -pedantic" as it only covers pointers.) c-family/c-format.c's check_format_types has: /* Don't warn about differences merely in signedness, unless -Wpedantic. With -Wpedantic, warn if the type is a pointer target and not a character type, and for character types at a second level of indirection. */ if (TREE_CODE (wanted_type) == INTEGER_TYPE && TREE_CODE (cur_type) == INTEGER_TYPE && (!pedantic || i == 0 || (i == 1 && char_type_flag)) && (TYPE_UNSIGNED (wanted_type) ? wanted_type == c_common_unsigned_type (cur_type) : wanted_type == c_common_signed_type (cur_type))) continue;