Skip to content

Commit a5e2759

Browse files
committed
Handle string literals in ArrayToPointerDecay
1 parent b38c414 commit a5e2759

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,17 +1739,16 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
17391739
break;
17401740
}
17411741
Convert(sub_expr);
1742-
switch (GetConstCastType(
1743-
expr->getType()->getPointeeType(),
1744-
sub_expr->getType()->getAsArrayTypeUnsafe()->getElementType())) {
1745-
case ConstCastType::MutableToConst:
1746-
StrCat(".cast_const()");
1747-
break;
1748-
case ConstCastType::ConstToMutable:
1749-
StrCat(".cast_mut()");
1750-
break;
1751-
default:
1752-
break;
1742+
bool dest_pointee_const =
1743+
expr->getType()->getPointeeType().isConstQualified();
1744+
if (clang::isa<clang::StringLiteral>(sub_expr) ||
1745+
clang::isa<clang::PredefinedExpr>(sub_expr)) {
1746+
StrCat(".as_ptr()");
1747+
if (!dest_pointee_const) {
1748+
StrCat(".cast_mut()");
1749+
}
1750+
} else {
1751+
StrCat(dest_pointee_const ? ".as_ptr()" : ".as_mut_ptr()");
17531752
}
17541753
break;
17551754
}

0 commit comments

Comments
 (0)