Skip to content

Translate void casts#47

Merged
nunoplopes merged 8 commits intoCpp2Rust:masterfrom
lucic71:void-cast
May 1, 2026
Merged

Translate void casts#47
nunoplopes merged 8 commits intoCpp2Rust:masterfrom
lucic71:void-cast

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented Apr 30, 2026

No description provided.

Comment thread cpp2rust/converter/converter.cpp Outdated

void Converter::ConvertVoidCastExpr(clang::ExplicitCastExpr *expr) {
PushExprKind push(*this, ExprKind::Void);
StrCat("let _ = ");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the let is needed. You can just evaluate the expression as a statement. No clone needed either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I used let _ = expr.clone() to avoid moving expr, but simply writing expr; is enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no, the move still ocurs if expr is not Copy, for example:

int *p;
(void) p;

So a clone is needed for those types

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I now add clone for non-Copy types

@lucic71 lucic71 marked this pull request as draft April 30, 2026 21:02
@lucic71 lucic71 marked this pull request as ready for review April 30, 2026 21:27
@nunoplopes nunoplopes merged commit abea5bf into Cpp2Rust:master May 1, 2026
9 checks passed
lucic71 added a commit to lucic71/cpp2rust that referenced this pull request May 3, 2026
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