Skip to content

Key rules through explicit casts and implicit wrappers - #556

Merged
nunoplopes merged 8 commits into
Cpp2Rust:masterfrom
lucic71:2-explicit-cast-expr-key
Oct 21, 2026
Merged

nunoplopes merged 8 commits into
Cpp2Rust:masterfrom
lucic71:2-explicit-cast-expr-key

Conversation

@lucic71

@lucic71 lucic71 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@nunoplopes
nunoplopes merged commit cab6a2b into Cpp2Rust:master Oct 21, 2026
9 checks passed
nunoplopes pushed a commit that referenced this pull request Oct 30, 2026
Fixes #556 

Adds rules for `std::vector<bool>::reference` and
`std::vector<bool>::iterator::reference`.

The reference of vector bool is not a real C++ `&`, instead it's a proxy
type that acts as a reference. GetDeclaredReturnType and
IgnoreParenNoopCasts take care of handling this.

Then, because in the following rule T1 lives in an undeduced context,
C++ cannot use overload resolution to resolve the type:

```cpp
template <typename T1>
typename std::vector<bool, T1>::reference f118(std::vector<bool, T1> &a0,
                                               std::size_t a1) {
  return a0.operator[](a1);
}
```

Instead we use two techniques to resolve T1:
1. Use the spelled name of the usage. For `std::vector<bool>::reference
r1 = v1[0]` the spelled name is `std::vector<bool>::reference`.
`reference` is a member of the owner `std::vector<bool,
alllocator<bool>>` so T1 becomes `allocator<bool>`
2. For `std::vector<bool>::iterator::reference` the owner is
`std::vector<bool>::iteartor` which is not the same as
`std::vector<bool, allocator<bool>>` which gives T1, so hop through
owners until we reach the correct one
joaotgouveia pushed a commit to joaotgouveia/cpp2rust that referenced this pull request Oct 30, 2026
Fixes Cpp2Rust#556

Adds rules for `std::vector<bool>::reference` and
`std::vector<bool>::iterator::reference`.

The reference of vector bool is not a real C++ `&`, instead it's a proxy
type that acts as a reference. GetDeclaredReturnType and
IgnoreParenNoopCasts take care of handling this.

Then, because in the following rule T1 lives in an undeduced context,
C++ cannot use overload resolution to resolve the type:

```cpp
template <typename T1>
typename std::vector<bool, T1>::reference f118(std::vector<bool, T1> &a0,
                                               std::size_t a1) {
  return a0.operator[](a1);
}
```

Instead we use two techniques to resolve T1:
1. Use the spelled name of the usage. For `std::vector<bool>::reference
r1 = v1[0]` the spelled name is `std::vector<bool>::reference`.
`reference` is a member of the owner `std::vector<bool,
alllocator<bool>>` so T1 becomes `allocator<bool>`
2. For `std::vector<bool>::iterator::reference` the owner is
`std::vector<bool>::iteartor` which is not the same as
`std::vector<bool, allocator<bool>>` which gives T1, so hop through
owners until we reach the correct one
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