[Issue 9975] pointsTo asserts because of false pointer in union

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 18 02:48:38 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9975



--- Comment #9 from monarchdodra at gmail.com 2013-06-18 02:48:36 PDT ---
(In reply to comment #8)
> (In reply to comment #7)
> > (In reply to comment #6)
> > > This function is used throughout std.algorithm so marking this as documented
> > > behavior is not a good solution because it mean basic algorithms like sort
> > > can't be used with such structs.
> > 
> > Which behavior exactly are you mentioning? And do you mean *any* structs, or
> > just structs containing unions?
> > 
> Returning false positives.
> Any struct that might trigger false positives on pointsTo.

It'd be even worst to have a false negative, IMO. Of course, the best would be
to not have any "false".

> It's really a serious issue, I stumbled over this while sorting JSON values.
> I don't think we can afford to say that sort or swap can't be used with
> algebraic types because they trigger false positive assertions.
> Of course this is mainly an issue with swap so we need to look at both sides.

Just to be clear, algebraic types don't trigger false positives.

The only things that answer true to pointsTo are true pointer types (including
slices and classes). Everything other basic type is statically known not to be
a pointer type. Basically, points to knows what is pointer type, and what
isn't. There are (AFAIK) no "false pointers"

The problem really only appears once unions get into the way.

If a union contains an int, and a pointer (which is basically the example
provided), then there is literally no way to know which of the union members
should be taken into account. The union legitimately contains both the states
pointsTo and !pointsTo :/ That's where the problem is. Given that pointsTo
anser true as soon as at least a member pointsTo something, the reasonable
answer to give in case of dual state is true...

It *is* a problem, but I don't think it is as big a problem as you think it is
(or at least, not in your wording of "sort can't be used with structs").

A tristate answer might be the answer. Given that pointsTo is mostly only ever
used in assertive conditions, we could assert only if pointsTo is true. If
pointsTo is "maybe", the swap can be more lenient and go ahead anyways...?

We'd need to have a tribool type in phobos first though, if we want to do this
in a (mostly) non breaking way.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list