From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47868 invoked by alias); 30 Sep 2016 21:48:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 47776 invoked by uid 89); 30 Sep 2016 21:48:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy= X-HELO: mail-oi0-f49.google.com Received: from mail-oi0-f49.google.com (HELO mail-oi0-f49.google.com) (209.85.218.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Sep 2016 21:48:25 +0000 Received: by mail-oi0-f49.google.com with SMTP id w11so145384229oia.2 for ; Fri, 30 Sep 2016 14:48:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=YXuwMbvloRRn51MRmQFoqSTPdxbtIDpngdW/TnLQBqQ=; b=JdDn7gGssTq3iBUGGtf91iiM/5hUBoynQAGOalr9kmdqWBcTEh9Xhq3yl8AsWX1v1B er2nQdsvWMRFBehTVWgmbBEwO+bb7c2aAlrGVB23BtdYgHHq88ko53Pmfq2uLZ/ZWLY0 s13/hMtO9JivIdTRn20LBTUezACdansakY6TQMMQNE764Pxh3X+O0yjauEvjR1eYLxUs YdJLO5MA15YGFEQgmMRNamCGNsrdwYNRySTKgYF5adplMA4kfB728sCRQOUw5KP4HkkM vNZum42JXD34qtwH/L1N2vII/ZDmrgoSA9J2ni8kDaMSULY5NCUvWFLUWL6VHce9W5F9 21iQ== X-Gm-Message-State: AA6/9RkpbtnKnPtl0S+rI1XkK0VnkSFKCGenSz+9N5uWJSgKugA+Uy0oYnh8KFKGD0yjJq+uPpqoI4u7E+aYcwo2 X-Received: by 10.202.216.139 with SMTP id p133mr9219934oig.83.1475272104311; Fri, 30 Sep 2016 14:48:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.105.167 with HTTP; Fri, 30 Sep 2016 14:48:03 -0700 (PDT) In-Reply-To: <20160930164337.GE3223@redhat.com> References: <20160910145843.GJ19950@redhat.com> <20160915121631.GY19950@redhat.com> <20160923131537.GB3223@redhat.com> <20160930164337.GE3223@redhat.com> From: Jason Merrill Date: Fri, 30 Sep 2016 22:16:00 -0000 Message-ID: Subject: Re: C/C++ PATCH to implement -Wpointer-compare warning (PR c++/64767) To: Marek Polacek Cc: GCC Patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-09/txt/msg02436.txt.bz2 On Fri, Sep 30, 2016 at 12:43 PM, Marek Polacek wrote: > On Fri, Sep 23, 2016 at 10:31:33AM -0400, Jason Merrill wrote: >> On Fri, Sep 23, 2016 at 9:15 AM, Marek Polacek wrote: >> > On Wed, Sep 21, 2016 at 03:52:09PM -0400, Jason Merrill wrote: >> >> On Mon, Sep 19, 2016 at 2:49 PM, Jason Merrill wrote: >> >> > I suppose that an INTEGER_CST of character type is necessarily a >> >> > character constant, so adding a check for !char_type_p ought to do the >> >> > trick. >> >> >> >> Indeed it does. I'm checking this in: >> > >> > Nice, thanks. What about the original patch? We still need to warn >> > (or error for C++11) for pointer comparisons. >> >> If we still accept pointer comparisons in C++, that's another bug with >> treating \0 as a null pointer constant. This seems to be because >> ocp_convert of \0 to int produces an INTEGER_CST indistinguishable >> from literal 0. > > I was trying to fix this in ocp_convert, by using NOP_EXPRs, but that wasn't > successful. But since we're interested in ==/!=, I think this can be fixed > easily in cp_build_binary_op. Actually, all that seems to be needed is using > orig_op as the argument to null_ptr_cst_p, but that wouldn't give the correct > diagnostics, so I did this. By checking orig_op we can see if the operands are > character literals or not, because orig_op is an operand before the default > conversions. What is wrong about the diagnostic from just using orig_op? "ISO C++ forbids comparison between pointer and integer" seems fine to me, and will help the user to realize that they need to index off the pointer. I see that some of the calls to null_ptr_cst_p in cp_build_binary_op have already been changed to check orig_op*, but not all. Let's update the remaining calls, that should do the trick without adding a new error. Jason