From 0582f0ef2bd1032b2c963019f1150b99224b9b3d Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 25 Apr 2026 15:31:34 +0100 Subject: [PATCH 1/2] Add const to BitArray opOpAssign!"~" and opBinary!"~" parameters --- std/bitmanip.d | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/std/bitmanip.d b/std/bitmanip.d index f8a97dfbf19..e1435064a48 100644 --- a/std/bitmanip.d +++ b/std/bitmanip.d @@ -1176,10 +1176,10 @@ public: } /********************************************** - * Sets the amount of bits in the `BitArray`. + * Sets the number of bits in the `BitArray`. * $(RED Warning: increasing length may overwrite bits in * the final word of the current underlying data regardless - * of whether it is shared between BitArray objects. i.e. D + * of whether it is shared between `BitArray` objects. i.e. D * dynamic array extension semantics are not followed.) */ @property size_t length(size_t newlen) pure nothrow @system @@ -2214,7 +2214,7 @@ public: /*************************************** * ditto */ - BitArray opOpAssign(string op)(BitArray b) pure nothrow return scope + BitArray opOpAssign(string op)(const BitArray b) pure nothrow return scope if (op == "~") { auto istart = _len; @@ -2231,7 +2231,7 @@ public: bool[] bb = [0,1,0]; auto a = BitArray(ba); - auto b = BitArray(bb); + const b = BitArray(bb); BitArray c; c = (a ~= b); @@ -2241,7 +2241,6 @@ public: assert(a[2] == 0); assert(a[3] == 1); assert(a[4] == 0); - assert(c == a); } @@ -2273,12 +2272,10 @@ public: } /** ditto */ - BitArray opBinary(string op)(BitArray b) const pure nothrow + BitArray opBinary(string op)(const BitArray b) const pure nothrow if (op == "~") { - BitArray r; - - r = this.dup; + BitArray r = this.dup; r ~= b; return r; } @@ -2289,8 +2286,8 @@ public: bool[] ba = [1,0]; bool[] bb = [0,1,0]; - auto a = BitArray(ba); - auto b = BitArray(bb); + const a = BitArray(ba); + const b = BitArray(bb); BitArray c; c = (a ~ b); From 37a3c015e000d5e5364cb617ddcfdde7e55c4eb4 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 25 Apr 2026 15:41:51 +0100 Subject: [PATCH 2/2] Add const for opCmp parameter too --- std/bitmanip.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/std/bitmanip.d b/std/bitmanip.d index e1435064a48..1c32e6aeb06 100644 --- a/std/bitmanip.d +++ b/std/bitmanip.d @@ -1744,7 +1744,7 @@ public: /*************************************** * Supports comparison operators for `BitArray`. */ - int opCmp(BitArray a2) const @nogc pure nothrow + int opCmp(const BitArray a2) const @nogc pure nothrow { const lesser = this.length < a2.length ? &this : &a2; immutable fullWords = lesser.fullWords; @@ -1791,8 +1791,8 @@ public: bool[] bf = [1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]; bool[] bg = [1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]; - auto a = BitArray(ba); - auto b = BitArray(bb); + const a = BitArray(ba); + const b = BitArray(bb); auto c = BitArray(bc); auto d = BitArray(bd); auto e = BitArray(be);