File tree Expand file tree Collapse file tree
cpp2rust/converter/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -490,8 +490,8 @@ void ConverterRefCount::EmitRustUnion(clang::RecordDecl *decl) {
490490 }
491491 StrCat (" )]" );
492492
493- StrCat (
494- std::format ( " pub struct {} {{ __store: libcc2rs::UnionStorage, }} " , name));
493+ StrCat (std::format ( " pub struct {} {{ __store: libcc2rs::UnionStorage, }} " ,
494+ name));
495495
496496 StrCat (std::format (" impl {}" , name));
497497 {
@@ -1487,6 +1487,32 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) {
14871487 return false ;
14881488 }
14891489
1490+ if (auto *parent =
1491+ clang::dyn_cast<clang::RecordDecl>(member->getDeclContext ());
1492+ parent && parent->isUnion () && clang::isa<clang::FieldDecl>(member)) {
1493+ std::string str;
1494+ {
1495+ Buffer buf (*this );
1496+ PushExprKind push (*this ,
1497+ isLValue () ? ExprKind::LValue : ExprKind::RValue);
1498+ Converter::ConvertMemberExpr (expr); // e.g. (*u.borrow()).i
1499+ str = std::move (buf).str ();
1500+ }
1501+ str += " ()" ;
1502+
1503+ if (isAddrOf ()) {
1504+ StrCat (str);
1505+ computed_expr_type_ = ComputedExprType::Pointer;
1506+ return false ;
1507+ }
1508+ if (isLValue ()) {
1509+ pending_deref_.set (str);
1510+ return false ;
1511+ }
1512+ StrCat (DerefPtrExpr (str, member->getType ()));
1513+ return false ;
1514+ }
1515+
14901516 std::string str;
14911517 if (known) {
14921518 str = GetMappedAsString (expr);
You can’t perform that action at this time.
0 commit comments