C/C++ PATCH to implement -Wpointer-compare warning (PR c++/64767)

Jason Merrill jason@redhat.com
Wed Sep 14 05:56:00 GMT 2016


On Sat, Sep 10, 2016 at 10:58 AM, Marek Polacek <polacek@redhat.com> wrote:
> Spurred by the recent <http://www.viva64.com/en/b/0425/> findings, I decided to
> implement a warning that warns when a pointer is compared with a zero character
> literal (constant), because this isn't likely to be intended.  So e.g.
>
>   ptr == L'\0'
>
> is probably wrong and should've been written as
>
>   ptr[0] == L'\0'
>
> Jonathan pointed out that this would actually be invalid C++11 since pointer
> conversions are only allowed for integer literals, not char literals.

Ah, indeed.  And if we fix that, we get an error rather than a
warning.  Maybe let's handle this by wrapping character literals in a
redundant NOP_EXPR?

Jason



More information about the Gcc-patches mailing list