Is an automatic string variable a dynamic array in the sense of sec. 10.11.2 "Identity Expression" par. 4?

kdevel kdevel at vogtner.de
Fri Jul 15 13:34:03 UTC 2022


The rule [1] states:

     For [...] dynamic arrays, identity is defined as referring to 
the same
     array elements and the same number of elements.

[BTW: Every two arrays having the same elements implies that they 
also have the same **number** of elements. Hence the second 
condition is redundant.]

In this piece of code [2]:

```
    void main ()
    {
       string s = null;
       string t = "";
       assert (s is t);
    }
```

the assertion trips although both conditions of the given rule 
are met.

The second condition of the rule is true: Both arrays have the 
same number of elements (zero). For the first condition to be 
false it requires an index position at which the elements of both 
arrays differ. Since there is no such position the first 
condition is **not** false, meaning it is also true.

Therefor the documentation does not document the actual behavior 
of D implementations (checked dmd and gdc). The issue is not 
restricted to the string type.



[1] https://dlang.org/spec/expression.html#identity_expressions
[2] https://issues.dlang.org/show_bug.cgi?id=17623


More information about the Digitalmars-d mailing list