Skip to content

Commit 5a610c8

Browse files
committed
Apply fix to refcount
1 parent bf1abb1 commit 5a610c8

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,12 +2758,8 @@ bool Converter::VisitInitListExpr(clang::InitListExpr *expr) {
27582758
StrCat(token::kComma);
27592759
}
27602760
} else {
2761-
if (expr->getNumInits() == 1 && qual_type->isArrayType() &&
2762-
qual_type->getArrayElementTypeNoTypeQual()->isCharType() &&
2763-
clang::isa<clang::StringLiteral>(
2764-
expr->getInit(0)->IgnoreParenImpCasts())) {
2765-
auto *init = expr->getInit(0);
2766-
ConvertVarInit(init->getType(), init);
2761+
if (IsInitExprOfStringLiteral(expr)) {
2762+
Convert(expr->getInit(0)->IgnoreParenImpCasts());
27672763
return false;
27682764
}
27692765
PushBracket bracket(*this);

cpp2rust/converter/converter_lib.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ bool IsAsciiStringLiteral(const clang::StringLiteral *str) {
255255
return true;
256256
}
257257

258+
bool IsInitExprOfStringLiteral(const clang::InitListExpr *expr) {
259+
auto type = expr->getType();
260+
return expr->getNumInits() == 1 && type->isArrayType() &&
261+
type->getArrayElementTypeNoTypeQual()->isCharType() &&
262+
clang::isa<clang::StringLiteral>(
263+
expr->getInit(0)->IgnoreParenImpCasts());
264+
}
265+
258266
std::vector<clang::CXXConstructorDecl *>
259267
GetTemplateInstantiatedCtors(clang::CXXRecordDecl *decl) {
260268
std::vector<clang::CXXConstructorDecl *> out;

cpp2rust/converter/converter_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ bool IsCallToOstream(clang::CallExpr *expr);
6767

6868
bool IsAsciiStringLiteral(const clang::StringLiteral *str);
6969

70+
bool IsInitExprOfStringLiteral(const clang::InitListExpr *expr);
71+
7072
std::vector<clang::CXXConstructorDecl *>
7173
GetTemplateInstantiatedCtors(clang::CXXRecordDecl *decl);
7274

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,12 @@ bool ConverterRefCount::VisitInitListExpr(clang::InitListExpr *expr) {
13971397
return false;
13981398
}
13991399

1400+
if (IsInitExprOfStringLiteral(expr)) {
1401+
Convert(expr->getInit(0)->IgnoreParenImpCasts());
1402+
computed_expr_type_ = ComputedExprType::FreshValue;
1403+
return false;
1404+
}
1405+
14001406
auto conv = getConversionKind();
14011407
// 2D arrays are FullRefCount'ed on the second level as well.
14021408
PushConversionKind push(

0 commit comments

Comments
 (0)