Skip to content

Commit 8f677b7

Browse files
authored
Fix ConvertVarInit: use &raw const/mut for global statics bound to reference params
1 parent b3def05 commit 8f677b7

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3479,9 +3479,14 @@ std::string Converter::GetUnsafeTypeAsString(clang::QualType qual_type) const {
34793479

34803480
void Converter::ConvertVarInit(clang::QualType qual_type, clang::Expr *expr) {
34813481
if (qual_type->isReferenceType() && !IsReferenceType(expr)) {
3482-
StrCat(token::kRef);
3483-
if (IsMut(qual_type)) {
3484-
StrCat(keyword_mut_);
3482+
if (IsGlobalVar(expr)) {
3483+
StrCat("&raw");
3484+
StrCat(IsMut(qual_type) ? keyword_mut_ : keyword::kConst);
3485+
} else {
3486+
StrCat(token::kRef);
3487+
if (IsMut(qual_type)) {
3488+
StrCat(keyword_mut_);
3489+
}
34853490
}
34863491
}
34873492
if (qual_type->isFunctionPointerType()) {

0 commit comments

Comments
 (0)