Repository navigation
Fix translations for unnamed function parameters - #197
Merged
nunoplopes merged 2 commits intoJun 20, 2026
Merged
Conversation
joaotgouveia
force-pushed
the
unnamed-function-parameters
branch
from
June 20, 2026 01:41
d540109 to
cd32680
Compare
joaotgouveia
added a commit
to joaotgouveia/cpp2rust
that referenced
this pull request
Oct 27, 2026
The current implementation of `GetNamedDeclAsString` defaults to
returning `self` whenever the declaration corresponds to an unnamed
function parameter. This leads to incorrect translations such as the
following:
```cpp
int main(int, char**) { return 0; }
```
```rust
fn main_0(self: i32, self: Ptr<Ptr<u8>>) -> i32 {
let self: Value<i32> = Rc::new(RefCell::new(self));
let self: Value<Ptr<Ptr<u8>>> = Rc::new(RefCell::new(self));
return 0;
}
```
This patch addresses this issue by changing `GetNamedDeclAsString` to
return `self` only when it is actually required, and `_` otherwise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current implementation of
GetNamedDeclAsStringdefaults to returningselfwhenever the declaration corresponds to an unnamed function parameter. This leads to incorrect translations such as the following:This patch addresses this issue by changing
GetNamedDeclAsStringto returnselfonly when it is actually required, and_otherwise.