The following simplified automatic reference counting implementation erroneously counts below zero. Passing a value of type S[1] to bar instead works correctly.
int counter = 0;
struct S {
bool constructed;
this(bool) { constructed = true; counter++; }
this(this) { if (constructed) counter++; }
~this() {
if (constructed) {
assert(counter > 0);
counter--;
}
}
}
void bar(S[1] s...) { S s2 = s[0]; }
void foo(S s) { bar(s); }
void main() { S s = S(true); foo(s); }
Output:
core.exception.AssertError@onlineapp.d(10): Assertion failure