This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Warning on move and dereference of unique_ptr in the same expression
- From: Allan Sandfeld Jensen <linux at carewolf dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Development <gcc at gcc dot gnu dot org>
- Date: Mon, 03 Feb 2020 22:08:27 +0100
- Subject: Re: Warning on move and dereference of unique_ptr in the same expression
- References: <4534615.31r3eYUQgx@twilight> <20200203204713.GG31864@redhat.com>
On Montag, 3. Februar 2020 21:47:13 CET Marek Polacek wrote:
> On Mon, Feb 03, 2020 at 09:26:40PM +0100, Allan Sandfeld Jensen wrote:
> > 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.
>
> You mean the application itself, not the compiler, presumably.
Of course.
>
> > 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?
>
> This should be defined in C++17, with P0145 in particular:
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0145r3.pdf
> which says that the expression that names the function is sequenced before
> every argument expression and every default argument.
>
Right thanks, that would explain why it worked consistently with the latest
gcc versions. I guess it is more of a corner case to ask for it being warned
about in --std=c++14 mode?
'Allan