Skip to content

Commit f9f633f

Browse files
committed
Fix Default for floating type
1 parent 2bb3063 commit f9f633f

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2604,7 +2604,7 @@ void Converter::ConvertIntegralToBooleanCast(clang::ImplicitCastExpr *expr) {
26042604
PushParen paren(*this);
26052605
Convert(sub_expr);
26062606
StrCat(token::kDiff);
2607-
StrCat(token::kZero);
2607+
StrCat(sub_expr->getType()->isFloatingType() ? "0.0" : "0");
26082608
computed_expr_type_ = ComputedExprType::FreshValue;
26092609
}
26102610

‎tests/unit/expr_as_bool_cpp.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,16 @@ int main() {
5555
assert(both_null(nullptr, nullptr) == 1);
5656
assert(both_null(p1, nullptr) == 0);
5757

58+
double d = 0.5;
59+
int taken = 0;
60+
if (d) {
61+
taken = 1;
62+
}
63+
assert(taken == 1);
64+
while (d) {
65+
d = 0.0;
66+
}
67+
assert(d == 0.0);
68+
5869
return 0;
5970
}

0 commit comments

Comments
 (0)