From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5400 invoked by alias); 28 Feb 2011 19:26:02 -0000 Received: (qmail 5389 invoked by uid 22791); 28 Feb 2011 19:26:01 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Feb 2011 19:25:53 +0000 From: "msebor at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/47931] New: missing -Waddress warning for comparison with NULL X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gmail 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-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Date: Mon, 28 Feb 2011 19:43:00 -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 X-SW-Source: 2011-02/txt/msg03133.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D47931 Summary: missing -Waddress warning for comparison with NULL Product: gcc Version: 4.4.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: msebor@gmail.com The -Waddress option causes gcc to emit a warning for suspicious tests of addresses of functions and objects. The patch that implemented the feature = and the current test for it indicate that the diagnostic is intended to include= the NULL pointer constant. However, gcc fails to diagnose the pointless compari= son against NULL in the test case below. http://gcc.gnu.org/ml/gcc-patches/2005-12/msg00972.html=20 http://gcc.gnu.org/viewcvs/trunk/gcc/testsuite/gcc.dg/Walways-true-1.c=20 I note that Wstring-literal-comparison-1.c test exercises the ability to diagnose comparisons of string literals against 0 while at the same time allowing such comparisons against null pointer constant. Perhaps this featu= re conflicts with the ability to issue warnings for constants of other types. Alternatively, it's possible that the ability to avoid a diagnostic when a = null pointer constant is used is deliberate. This is a request to either issue the warning in all cases, or to document = the existing behavior so that it can be relied on with some assurance that it w= ill continue to work this way in future versions of gcc. $ cat -n t.c && gcc -Waddress -c t.c 1 #define NULL (void*)0 2 3 int i; 4 5 int f() { return &i !=3D 0; } 6 int g() { return &i !=3D NULL; } t.c: In function =E2=80=98f=E2=80=99: t.c:5: warning: the address of =E2=80=98i=E2=80=99 will never be NULL