Cpp2Rust: Translates C++ to safe Rust automatically

(github.com)

41 points | by signa11 7 hours ago

6 comments

  • crnakfls 1 hour ago
    > 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.
    • antiframe 1 hour ago
      So, most C++ code I have seen in my forty years of coding.
    • bitwizeshift 1 hour ago
      Lol, “user defined copy/move constructors” That’s actually so many types that would define this
  • logicchop 1 hour ago
    If I can autoport my C++ to Rust, and the port is confirmed identical, and the Rust is confirmed safe, can't I use that to reason about the safety of my C++? Is safe C++ just a matter of proving it has a safe Rust equivalent?
    • johnbender 1 hour ago
      It depends on what “confirmed identical” means. Most compilers (or translators as you like) only guarantee that the output program represents a subset of the behaviors of the input program so it could be that subset is the “safe as in Rust” subset.
    • _flux 1 hour ago
      The conversions seem to use (sometimes?) unsafe blocks.
  • z_open 3 hours ago
    Why does the example not show an example of unsafe C++?
  • IshKebab 1 hour ago
    Yeah the readme definitely needs some non-trivial examples. How does this handle raw pointers? Operator overloading? Inheritance?
  • dmitrygr 1 hour ago
    The original paper quoth:

    > our reference-counted translation model, where every variable is pessimistically wrapped inside a Rc<RefCell<T>> type, checks that would usually execute at compile-time are shifted to run time, degrading performance.

  • migueldeicaza 2 hours ago
    codex "/goal port this codebase from c++ to rust"