Is alias equality inconsistent?

Jens Mueller jens.k.mueller at gmx.de
Fri May 13 12:55:36 PDT 2011


Jonathan M Davis wrote:
> On 2011-05-13 12:11, Jens Mueller wrote:
> > Hi,
> > 
> > I find that comparing for alias equality is a bit odd. Maybe somebody
> > can shed some light into it.
> > 
> > int a = 1;
> > int b = 1;
> > assert(a is b);
> > 
> > but
> > 
> > int[1] aFixedArray = [1];
> > int[1] bFixedArray = [1];
> > assert(aFixedArray !is bFixedArray);
> > 
> > It behaves as specified in TDPL p. 57:
> > "If a and b are arrays or class references, the result is true if and
> > only if a and b are two names for the same actual object;
> > Otherwise, a is b is the same as a == b."
> > 
> > But fixed-size arrays have value semantics as int, float etc. So why is
> > alias equality not consistent with value vs. reference semantics? Why
> > this exception for fixed-size arrays?
> 
> I'm surprised that is works with value semantics at all. I would have expected 
> that to be a compiler error. Barring that, I would have expected it to be 
> false for value types unless a variable was compared with itself with is. This 
> definitely seems off.

Yes. That would be fine with me. a is b would tell whether something is
the same in regard to memory.

Jens


More information about the Digitalmars-d mailing list