Skip to content

C++: fix implicit copy assignment of array members - #9240

Open
abcz-wang wants to merge 1 commit into
diffblue:developfrom
abcz-wang:fix/cpp-array-copy-assignment
Open

abcz-wang wants to merge 1 commit into
diffblue:developfrom
abcz-wang:fix/cpp-array-copy-assignment

Conversation

@abcz-wang

Copy link
Copy Markdown

Implicit copy assignment of a class with an array member and a user-provided default constructor aborts in default_assignop_value. Require the array-size conversion to succeed before dereferencing its optional result.

Fixing that check exposes a second abort in copy_array: index_exprt requires already-typechecked array operands, but these expressions are generated before type checking. Construct the frontend index expressions with binary_exprt so their operands and result types can be resolved by the subsequent type-checking pass.

Adds a regression checking that both array elements are copied correctly.

Fixes #9239.

Validation on macOS arm64, Apple Clang 21, based on develop 5783f861:

  • New regression aborts on the unmodified development build and passes with this fix.

  • 17 C++ regressions pass with --validate-goto-model --validate-ssa-equation (assignment, arrays, and constructors); 4 additional cases are skipped by the runner.

  • Mutating either expected copied value correctly produces VERIFICATION FAILED.

  • clang-format 15 reports no changes on the PR diff; git diff --check passes.

  • Each commit message has a non-empty body, explaining why the change was made.

  • Methods or procedures added are documented (none added).

  • User-visible behaviour is documented (restores existing C++ copy-assignment semantics; no new feature or option).

  • Regression tests are included in the same commit as the fix.

  • Performance claims include data points (no performance claims).

  • The PR is restricted to one bugfix.

  • No unrelated whitespace or formatting changes.

Require a successful array-size conversion before dereferencing its optional result. Build the generated index expressions without index_exprt, whose preconditions require operands to be typechecked already.

Add Assignment_Array_Member to check both copied elements. The new test aborts before the fix and passes afterwards. Tested with GOTO/SSA validation: 17 related C++ regressions pass (4 additional cases skipped by the runner); mutating either expected copied value fails verification.

Fixes diffblue#9239.

This branch has not been deployed

No deployments
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.

C++ implicit copy assignment for array members aborts in default_assignop_value (inverted CHECK_RETURN)

1 participant