Live data from Hacker News

Cpp2Rust: Translates C++ to safe Rust automatically

github.com

11–20 of 22 posts

Re: Cpp2Rust: Translates C++ to safe Rust automatically

#11
post #8

> Notable unsupported constructs include: union, volatile, goto, exceptions, bitfields, placement new, user-defined copy/move constructors, dynamic_cast, const_cast, base classes with fields or non-virtual methods, multiple inheritance, and multi-threaded code.

Lol, “user defined copy/move constructors” That’s actually so many types that would define this

Re: Cpp2Rust: Translates C++ to safe Rust automatically

#13
If the concern is memory safety, I'd invite comparison with migration to the scpptool-enforced memory-safe subset of C++ [1]. If your C++ code is "idiomatic modern" C++, then the changes required to conform to the safe subset (in an idiomatic way) are often modest, and as demonstrated in the link, often something an LLM can handle for you. Since the safe subset does not impose a universal restriction on mutable aliasing the way Rust does, it doesn't require wrapping everything in `RefCell`s or anything like that (unless the objects in question are being shared between threads).

If your C++ code is more "legacy" than "modern", the migration is generally still straightforward, but will often involve additional run-time overhead, like it does with this cpp2rust, but to a lesser degree I think. Objects allocated on the stack can (safely) remain allocated on the stack even when they are the target of pointers. And still, no `RefCell` equivalents are required for objects that aren't shared between threads.

[1] https://github.com/duneroadrunner/scpptool/blob/master/READM...

Re: Cpp2Rust: Translates C++ to safe Rust automatically

#14
Interesting, but unpractical. As I know there is no way to perform automatic translation from one programming language to another without producing code which looks terrible in the destination language.

In this particular example I see no real safety benefits. If the source program is buggy, the result translated program willcrash at runtime, but if it's (mostly) bug-free and UB-free, such translation gives no benefits.

Re: Cpp2Rust: Translates C++ to safe Rust automatically

#16
post #8

> Notable unsupported constructs include: union, volatile, goto, exceptions, bitfields, placement new, user-defined copy/move constructors, dynamic_cast, const_cast, base classes with fields or non-virtual methods, multiple inheritance, and multi-threaded code.

From the point of view of C++26, which is already ratified, and half implemented in GCC 16, I think your list should even be longer.

The readme is rather slim on C++ versions.

Re: Cpp2Rust: Translates C++ to safe Rust automatically

#17
post #8

> Notable unsupported constructs include: union, volatile, goto, exceptions, bitfields, placement new, user-defined copy/move constructors, dynamic_cast, const_cast, base classes with fields or non-virtual methods, multiple inheritance, and multi-threaded code.

Lol, “user defined copy/move constructors” That’s actually so many types that would define this

Base classes with fields or non-virtual methods are not exactly rare neither.
Post reply on HN