From cd57b0225b200ba19d5be94d121138a7f088f589 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 9 Oct 2026 12:34:49 +0100 Subject: [PATCH 1/2] Fix converter crashes around freshness --- cpp2rust/converter/converter.cpp | 1 + cpp2rust/converter/models/converter_refcount.cpp | 4 +--- tests/unit/stmt_expr.cpp | 8 ++++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index b63c7fcb3..8d03faf9c 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -3138,6 +3138,7 @@ bool Converter::VisitStmtExpr(clang::StmtExpr *expr) { Convert(s); } } + SetFreshType(expr->getType()); return false; } diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 9a5f74873..66f0cce14 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -1770,9 +1770,7 @@ bool ConverterRefCount::VisitReturnStmt(clang::ReturnStmt *stmt) { bool ConverterRefCount::VisitStmtExpr(clang::StmtExpr *expr) { PushConversionKind push(*this, ConversionKind::FullRefCount); - Converter::VisitStmtExpr(expr); - SetFreshType(expr->getType()); - return false; + return Converter::VisitStmtExpr(expr); } void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) { diff --git a/tests/unit/stmt_expr.cpp b/tests/unit/stmt_expr.cpp index bae4c3d05..7defffb86 100644 --- a/tests/unit/stmt_expr.cpp +++ b/tests/unit/stmt_expr.cpp @@ -32,5 +32,13 @@ int main() { }); inner; }) == 100); + + ({ counter++; }); + __extension__({ + if (counter != 2) { + counter = 2; + } + }); + assert(counter == 2); return 0; } From cec2ad75c1c08de916a942f3b07c037d132ecc2c Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 9 Oct 2026 18:20:51 +0100 Subject: [PATCH 2/2] Update tests --- tests/unit/out/refcount/stmt_expr.rs | 9 +++++++++ tests/unit/out/unsafe/stmt_expr.rs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/unit/out/refcount/stmt_expr.rs b/tests/unit/out/refcount/stmt_expr.rs index b8e972119..ce945a580 100644 --- a/tests/unit/out/refcount/stmt_expr.rs +++ b/tests/unit/out/refcount/stmt_expr.rs @@ -41,6 +41,15 @@ fn main_0() -> i32 { inner } == 100) ); + { + counter.postfix_inc() + }; + { + if (counter != 2) { + counter = 2; + } + }; + assert!((counter == 2)); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/stmt_expr.rs b/tests/unit/out/unsafe/stmt_expr.rs index a308f16e0..1bf37d013 100644 --- a/tests/unit/out/unsafe/stmt_expr.rs +++ b/tests/unit/out/unsafe/stmt_expr.rs @@ -43,6 +43,15 @@ unsafe fn main_0() -> i32 { inner }) == (100)) ); + { + counter.postfix_inc() + }; + { + if ((counter) != (2)) { + counter = 2; + } + }; + assert!(((counter) == (2))); return 0; } pub unsafe fn __cpp2rust_init_globals() {}