This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Ping: Ping: [Patch][RFA] Warn if pointer is initialized to 'false'
- From: Dave Korn <dave dot korn dot cygwin at googlemail dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: Simon Baldwin <simonb at google dot com>, gcc-patches at gcc dot gnu dot org, Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Date: Mon, 01 Feb 2010 00:38:06 +0000
- Subject: Re: Ping: Ping: [Patch][RFA] Warn if pointer is initialized to 'false'
- References: <3ea232e01001280139j3f5396f9ua5280e359d77b416@mail.gmail.com> <4B65F392.6050109@codesourcery.com>
On 31/01/2010 21:18, Mark Mitchell wrote:
> Simon Baldwin wrote:
>
>>>> Confirmed C++ dejagnu testsuite parity with the unpatched gcc, and verified
>>>> bootstrap of C/C++ on x86_64.
>>>>
>>>> Okay for trunk? Would pedwarn be preferable to warning?
>
> This patch is OK.
>
>>>> * call.c (conversion_null_warnings): Warn if 'false' is used in
>>>> pointer assignment or initialization.
>
> No, I don't think so. IIUC, false is a valid null pointer constant, so
> there's no reason for a pedwarn; even when pedantic, this code is legal,
> if odd.
>
> The reason is that [pointer conversions] says that a null pointer
> constant "is an integral constant expression with integer type that
> evaluates to zero". false is of type bool, which is an integral type,
> and [fundamental types] defines "integer type" as a synonym for
> "integral type" (with the consequence that the set of integer types is
> not the union of the set of signed integer types and the set of unsigned
> integer types).
Yeah, but it's a bit of a nuisance when you accidentally "return false;"
from something that returns a std::string (-> calls ctor string::string((const
char *)0), which is illegal and generally segfaults), and you can't get a
warning about it.
cheers,
DaveK