News for hackers. Stuff that matters.
Re:New C++ features in GCC 12 by Tyr42 on Sunday May 01, 2022 @01:50PM (#31227036)
Wait, but what if you have

std::string str1{"Apple"}; std::string str2 = std::move(str1);

Isn't str1 in an invalid (err, unspecified?) state and you shouldn't use it? It's not `null` sure, but it's not good to use.

Re:New C++ features in GCC 12 by lenkite on Sunday May 01, 2022 @02:22PM (#31227378)
This issue is caught and flagged by clang-tidy. Though technically the standard says it is in valid but un-specified state. Because of short string optimisation, the move might be possibly a copy, so one should not rely on the contents being empty.
Re:New C++ features in GCC 12 by deschutes on Sunday May 01, 2022 @03:47PM (#31228044)
Clang tidy covers only the most trivial use after move scenarios. It's useful coverage but isn't and never will be complete like the rust borrow checker.
Re:New C++ features in GCC 12 by jcelerier on Sunday May 01, 2022 @05:53PM (#31229062)
No, you can absolutely use it (but you most likely want to clear() or assign an empty string to it before doing e.g. push_back as move does not necessarily clear the moved-from object - std::move(some_int) won't clear the int)
Re:New C++ features in GCC 12 by Tyr42 on Monday May 02, 2022 @07:33PM (#31242509)
I mean, it won't have a useful value, so I need to re assign to it, at which point I could just be using a new variable right?

It might not be null, but I can't do much more with it than I can with null. I need to assign something new first

Re:New C++ features in GCC 12 by jcelerier on Wednesday May 04, 2022 @01:14PM (#31263250)
> I mean, it won't have a useful value, so I need to re assign to it, at which point I could just be using a new variable right?

I have a hard time understanding why "I could just be using a new variable" follows from "it won't have a useful value".