Skip to content

Destroy array elements in decreasing order in constant evaluation [GH #400] - #418

Merged
wchilders-nvidia merged 1 commit into
mainfrom
fix/400
Oct 28, 2026
Merged

wchilders-nvidia merged 1 commit into
mainfrom
fix/400

Conversation

@daveedvdv-nvidia

@daveedvdv-nvidia daveedvdv-nvidia commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #400.

During constant evaluation, the elements of an array were destroyed in increasing order of their index, but [class.dtor] and [expr.delete] require decreasing order. This changes the three places where the interpreter destroys array elements:

  • perform_destructions (registered destructions of complete objects, e.g., local arrays and temporaries),
  • the destruction of array members in the cleanup phase of process_dtor_work, and
  • the destruction of the elements of an array by a delete[] expression in do_constexpr_delete.

Tests: new changes/gh-400.sft.cpp.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed array destruction order during C++20 constant evaluation. Array elements, including those in multidimensional arrays and class members, are now destroyed in reverse order, matching expected C++ behavior. This also applies to arrays released with delete[]; scalar destruction behavior is unchanged.

…400]

During constant evaluation, the elements of arrays (complete objects, array
members, and arrays destroyed by a delete[] expression) are now destroyed in
decreasing order of their index, instead of in increasing order.
@daveedvdv-nvidia
daveedvdv-nvidia requested a review from a team October 28, 2026 14:41
@daveedvdv-nvidia daveedvdv-nvidia self-assigned this Oct 28, 2026
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8acf0fdd-509c-4743-9fb3-9cea5f44cb73
Commits

Reviewing files that changed from the base of the PR and between 4cc57d4 and d176b48.

Files selected for processing: 4
  • src/interpret.c
  • src/pending_changes/gh-400-array-destruction-order.txt
  • tests/tests/changes/.gh-400.rto/default.1.1.txt
  • tests/tests/changes/gh-400.sft.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

Constant evaluation now destroys array elements from last to first in array cleanup and dynamic deallocation. Regression tests cover local, multidimensional, and member arrays, plus delete[] and scalar delete. Non-array destruction behavior is unchanged.

Changes: Constant-evaluation array destruction

Layer / File(s) Summary
Reverse-order destruction
src/interpret.c
Array cleanup and dynamic deallocation now process elements from last to first. Non-array destruction behavior is unchanged.
Regression tests and changelog
tests/tests/changes/.gh-400.rto/default.1.1.txt, tests/tests/changes/gh-400.sft.cpp, src/pending_changes/gh-400-array-destruction-order.txt
C++20 tests check destruction order for local, multidimensional, and member arrays, user-defined destructors, delete[], and scalar delete. The changelog describes the issue.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Suggested reviewers: wchilders-nvidia

Merge Risk: Minimal · up to d176b

Array destruction now proceeds in reverse order. No merge-blocking issue was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: array elements are destroyed in decreasing order during constant evaluation. It also identifies the related issue.
Linked Issues check Passed Issue #400 requires decreasing destruction order for local arrays, array members, and arrays destroyed by delete[]. src/interpret.c now iterates from n or length down to 1 in `perform_destruct…
Out of Scope Changes check Passed The changes stay within issue #400. The implementation changes only constant-evaluation destruction order. The changelog and regression test document and verify the fix. The scalar delete test verif…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #400 requires decreasing destruction order for local arrays, array members, and arrays destroyed by delete[]. src/interpret.c now iterates from n or length down to 1 in perform_destructions, process_dtor_work cleanup, and do_constexpr_delete. The new C++20 test covers local, multidimensional, member, user-defined-destructor member, and delete[] cases with reverse-order static_assert checks.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #400. The implementation changes only constant-evaluation destruction order. The changelog and regression test document and verify the fix. The scalar delete test verifies unchanged non-array behavior.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (3 skipped: 2 unsupported, 1 too large.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for d176b48f7d41:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for d176b48f7d41:

CI success.

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@wchilders-nvidia
wchilders-nvidia added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit 2f08b84 Oct 28, 2026
21 checks passed
@wchilders-nvidia
wchilders-nvidia deleted the fix/400 branch October 28, 2026 21:48
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.

Constant evaluation: array elements are destroyed in increasing order

3 participants