This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Warning on move and dereference of unique_ptr in the same expression
- From: Allan Sandfeld Jensen <linux at carewolf dot com>
- To: GCC Development <gcc at gcc dot gnu dot org>
- Date: Mon, 03 Feb 2020 21:26:40 +0100
- Subject: Warning on move and dereference of unique_ptr in the same expression
Hello gcc
I have now twice hit obscure bugs in Chromium that crashed on some compilers
but not on others, and didn't produce any warnings on any compiler. I would
like to know if this code is as undefined as I think it is, and if it would
make sense to have gcc warn about it.
Both cases basically has this form:
std::unique_ptr<A> a;
a->b->callMethod(something, bind(callback, std::move(a)));
This crashed with MSVC and gcc 5, but not with newer gcc or with clang.
When it crashes it is because the arguments and the move therein have been
evaluated before a->b is resolved.
I assume this is undefined behavior? So why isn't the warning for using and
modifying in the same expression triggered?
Best regards
'Allan