This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ping: Ping: [Patch][RFA] Warn if pointer is initialized to 'false'


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]