Remix.run Logo
lII1lIlI11ll 4 days ago

> Memory safety isn't much of a problem in C++ anymore with smart pointers, std::move.

Of course it is! You can still access an object after std::moving it somewhere, return references to local stack variables from functions, double-delete (or zero!), use uninitiated variables and do bunch of other things that rightfully caused notoriety C++ has got. And am saying it as someone who writes C++ every workday, unfortunately.

throwaway18373 4 days ago | parent [-]

You "write C++ every workday" and don't even know that moved-from objects are guaranteed to be valid?

> return references to local stack variables from functions

> use uninitiated variables

Any properly configured compiler will catch and warn about those errors.

> double-delete (or zero!)

Not a real issue if you're using smart pointers.

Sure, you can program with no compiler warnings and no smart pointers—but nothing is stopping you from wrapping your entire Rust program in "unsafe" and doing all those things there as well. Programming languages can only do so much to save people from their own incompetence.

lII1lIlI11ll 3 days ago | parent [-]

> You "write C++ every workday" and don't even know that moved-from objects are guaranteed to be valid?

I'm getting strong Dunning–Kruger vibes from your reply. Yes, moved-from objects are in valid but often unspecified state even in STL, not to mention custom code in most C++ projects I had experience with [0][1].

> Any properly configured compiler will catch and warn about those errors.

No true Scotsman compilers...

> Not a real issue if you're using smart pointers. Sure, you can program with no compiler warnings and no smart pointers...

Yeah, the good-old tried-and-true "just always manage your memory correctly and avoid having bugs" way of writing C++ software that have been working out so well.

[0] https://wiki.sei.cmu.edu/confluence/display/cplusplus/EXP63-...

[1] https://stackoverflow.com/a/17735913