On Fri, Feb 19, 2016 at 01:04:04PM +0100, Petr Spacek wrote:
> On 19.2.2016 08:50, Jakub Jelinek wrote:
> > On Fri, Feb 19, 2016 at 03:12:29AM +0100, Kevin Kofler wrote:
> >> Jakub Jelinek wrote:
> >>> ASSERT(this) is pointless, it is testing if undefined behavior didn't
> >>> happen after the fact, that is just too late.  As I said, use
> >>> -fsanitize=undefined to make sure you don't call methods on nullptr.
> >>
> >> Doesn't -fno-delete-null-pointer-checks make such ASSERTs work (and also 
> >> explicit "if (this)" type checks)? I read that that flag fixes programs 
> >> which rely on "if (this)" checks.
> > 
> > That switch allows to work around buggy programs, at the cost of optimizing
> > them less, yes.  In any case, such programs should be fixed, this must be
> > always non-NULL, methods can't be called on NULL pointers.
> 
> Could you elaborate on this, please?
> 
> What is wrong with
>     if (ptr != NULL)
> ?
> 
> What standard says that it is wrong?

It's about checking whether "this", in C++, is NULL.  Since any call on a null
pointer is undefined behavior, any code relying on such checks is non-standard.

        Marek
--
devel mailing list
devel@lists.fedoraproject.org
http://lists.fedoraproject.org/admin/lists/devel@lists.fedoraproject.org

Reply via email to