Skip to content

Fix rvalue usage of vector<bool>::reference - #576

Merged
nunoplopes merged 4 commits into
Cpp2Rust:masterfrom
lucic71:1234
Nov 1, 2026
Merged

nunoplopes merged 4 commits into
Cpp2Rust:masterfrom
lucic71:1234

Conversation

@lucic71

@lucic71 lucic71 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

vector<bool>::reference is not a real reference type, it's a proxy. Handle that using ExprMapsValueToPointer which checks values, the vector bool reference, translated as pointers.

Also use __a0 = a0 in the vector rules because I++ runs 2 times otherwise.

nunoplopes pushed a commit that referenced this pull request Nov 1, 2026
Make substring calls evaluate their receiver and arguments once in both
output models. Duplicating an operand during inline substitution can
change both the selected bytes and caller state; this handles the
substring case of #575.

The side-effect cases in [tests/unit/string.cpp](tests/unit/string.cpp)
compare substring bytes and final counters with C++ for position, count
and receiver expressions.

- Capture the receiver and arguments in a tuple match, which also keeps
temporary receivers alive until the substring has been copied.
- Borrow the source after evaluating the arguments, so argument
expressions can modify it before the slice is read.
- Materialize temporary receivers before taking their address in the
unsafe converter.

The result remains an independent, null-terminated copy of the selected
slice. No whole-source clone is introduced; reference-counted receivers
must now be addressable. Existing range clipping and overflow handling
are unchanged.

## Testing

- `lit` on `tests/unit/string.cpp` and `tests/unit/string_substr.cpp`
(Linux, Release build): pass. Both fail without this change.
- Full suite (unit, ub and multi-file) on Linux at ce0915c: 1142 pass /
14 xfail / 0 fail before; 1144 pass / 14 xfail / 0 fail with this
change. The two new passes are the tests above. On macOS, one expected
output in `string_substr.cpp` hard-codes the libstdc++ `std::string`
size; a fix for that follows.
- `clang-format --dry-run --Werror` on the changed C++ files, `rustfmt
--check` on the changed rule files, and `cargo clippy --all-targets
--all-features -- -Dwarnings` on `rules/`: clean.

[tests/unit/string_substr.cpp](tests/unit/string_substr.cpp) checks
receiver-before-argument ordering, source mutations in either argument,
independent result storage, and temporary, pointer, field and
container-element receivers. The generated Rust expectations cover both
models.

Related work: #576 changes
vector proxy handling in the converter and binds repeated operands in
vector rules; this change handles substring expansion.

[Case and evidence](<https://app.perfloop.ai/t/oss/case_gs6rt5cvpd>)

---

Generated by [Perfloop](https://app.perfloop.ai). Human sponsor: [Tomás
Senart](https://github.com/tsenart).

---------

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Tomás Senart <ts@perfloop.ai>
@nunoplopes
nunoplopes merged commit a25706b into Cpp2Rust:master Nov 1, 2026
9 checks passed
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.

2 participants