From 8d75e0af964c979bf4107a72d7189fcc3346af52 Mon Sep 17 00:00:00 2001 From: jmh530 Date: Sun, 4 Oct 2026 21:31:28 -0400 Subject: [PATCH] Fix ndslice indexed unary safety checks for narrow integers Discard the safety-check helper's result instead of returning a reference to its local parameter, avoiding optimized GDC warnings. Test indexed increment, decrement, and reference-return behavior for ubyte, ushort, uint, and ulong. Fixes #483 AI-Assisted-By: Codex (GPT-6 Astra Medium) --- source/mir/ndslice/slice.d | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/source/mir/ndslice/slice.d b/source/mir/ndslice/slice.d index fa8f9e75..b584d67c 100644 --- a/source/mir/ndslice/slice.d +++ b/source/mir/ndslice/slice.d @@ -3323,10 +3323,10 @@ public: // @@@workaround@@@ for Issue 16473 //if (op == `++` || op == `--`) { - // check op safety - static auto ref fun(DeepElement t) @safe + // Check op safety without returning a reference to the local value. + static void fun(DeepElement t) @safe { - return mixin(op ~ `t`); + cast(void) mixin(op ~ `t`); } return mixin (op ~ `_iterator[indexStride(_indices)]`); } @@ -3342,6 +3342,25 @@ public: assert(a[1, 2] == 1); } + // https://github.com/libmir/mir-algorithm/issues/483 + // Check that indexed increment and decrement compile for narrow integers + // with optimized GDC and -Werror, and still return the cell by reference. + static if (doUnittest) + @safe pure nothrow @nogc version(mir_ndslice_test) unittest + { + import std.meta: AliasSeq; + static foreach (T; AliasSeq!(ubyte, ushort, uint, ulong)) + {{ + T[6] data; + auto a = data[].sliced(2, 3); + assert(++a[1, 2] == 1); + assert(data[5] == 1); + assert(--a[1, 2] == 0); + (++a[1, 2]) = T(7); + assert(data[5] == 7 && a[0, 0] == 0); + }} + } + // Issue 16473 static if (doUnittest) @safe pure nothrow version(mir_ndslice_test) unittest