From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: C/C++ PATCH to implement -Wpointer-compare warning (PR c++/64767)
Date: Fri, 30 Sep 2016 22:16:00 -0000 [thread overview]
Message-ID: <CADzB+2ncEWdsa+zezV0aOz95-AFjKTAzdpQBCPp5fwPr2E9RkQ@mail.gmail.com> (raw)
In-Reply-To: <20160930164337.GE3223@redhat.com>
On Fri, Sep 30, 2016 at 12:43 PM, Marek Polacek <polacek@redhat.com> 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 <polacek@redhat.com> 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 <jason@redhat.com> 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
next prev parent reply other threads:[~2016-09-30 21:48 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-10 15:06 Marek Polacek
2016-09-10 15:13 ` Jakub Jelinek
2016-09-10 15:48 ` Marek Polacek
2016-09-14 5:56 ` Jason Merrill
2016-09-15 12:31 ` Marek Polacek
2016-09-19 19:51 ` Jason Merrill
2016-09-21 19:55 ` Jason Merrill
2016-09-23 13:29 ` Marek Polacek
2016-09-23 14:37 ` Jason Merrill
2016-09-30 16:52 ` Marek Polacek
2016-09-30 17:22 ` Martin Sebor
2016-09-30 19:52 ` Martin Sebor
2016-09-30 20:02 ` Marek Polacek
2016-09-30 22:16 ` Martin Sebor
2016-09-30 22:16 ` Jason Merrill [this message]
2016-10-01 14:41 ` Marek Polacek
2016-10-02 18:43 ` Jason Merrill
2017-01-04 6:56 ` Eric Gallager
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADzB+2ncEWdsa+zezV0aOz95-AFjKTAzdpQBCPp5fwPr2E9RkQ@mail.gmail.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=polacek@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).