Re: GCC 6 -Wnonnull is too aggressive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/02/16 12:04, Petr Spacek wrote:

Could you elaborate on this, please?

What is wrong with
     if (ptr != NULL)
?

What standard says that it is wrong?

That isn't what's wrong. What is wrong is the method call that got you there. You have a method like this:

void foo()
{
  if (this != NULL) ...
}

and then you invoke it with a null pointer:

xxx->foo();

and it is that call that is not allowed by the standard when xxx is null.

So the compiler is allowed to assume that this will never be null in a method, because calling a method on a null pointer is not allowed, so it can just remove your null test in the method.

Then when you do call it on a null pointer you crash because the method is not doing the null test and just tries to access members of the object.

Tom

--
Tom Hughes (tom@xxxxxxxxxx)
http://compton.nu/
--
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxxx
http://lists.fedoraproject.org/admin/lists/devel@xxxxxxxxxxxxxxxxxxxxxxx




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux