Skip to content

Fix indexed ndslice increment and decrement safety checks on GDC - #484

Open
jmh530 wants to merge 1 commit into
libmir:masterfrom
jmh530:codex/ndslice-unary-safety-check
Open

jmh530 wants to merge 1 commit into
libmir:masterfrom
jmh530:codex/ndslice-unary-safety-check

Conversation

@jmh530

@jmh530 jmh530 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

The safety-check helper for indexed unary operations returns auto ref from a value passed by value. For ubyte and ushort, optimized GDC 14 and 15 diagnose this as returning a reference to a local parameter, causing builds with -Werror to fail.

Change the helper to return void and discard the expression result. It still checks that the operation is @safe; the actual indexed operation and its reference-return behavior remain unchanged.

Add tests covering increment, decrement, and assignment through the returned reference for ubyte, ushort, uint, and ulong.

Validation:

  • Reproduced the original warning on GDC 14.2 and 15.2.
  • The focused test passes optimized compilation with -Wall -Werror and runs successfully on both GDC versions.
  • Optimized ndslice unittests pass on DMD 2.113 and LDC 1.41: 19 modules each.

Fixes #483.

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 libmir#483

AI-Assisted-By: Codex (GPT-6 Astra Medium)
@jmh530

jmh530 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Only failure is Circle CI, which is unrelated to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ndslice unary-operation safety helper causes optimized GDC builds to fail for narrow integers

1 participant