public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Help compiler detect invalid code
Date: Fri, 27 Sep 2019 11:24:00 -0000	[thread overview]
Message-ID: <20190927112424.GV9487@redhat.com> (raw)
In-Reply-To: <96b51704-67fe-3ac4-405c-6997151d926c@gmail.com>

On 20/09/19 07:08 +0200, François Dumont wrote:
>I already realized that previous patch will be too controversial to be 
>accepted.
>
>In this new version I just implement a real memmove in __memmove so 

A real memmove doesn't just work backwards, it needs to detect any
overlaps and work forwards *or* backwards, as needed.

I think your change will break this case:

#include <algorithm>

constexpr int f(int i, int j, int k)
{
  int arr[5] = { 0, 0, i, j, k };
  std::move(arr+2, arr+5, arr);
  return arr[0] + arr[1] + arr[2];
}

static_assert( f(1, 2, 3) == 6 );

This is valid because std::move only requires that the result iterator
is not in the input range, but it's OK for the two ranges to overlap.

I haven't tested it, but I think with your change the array will end
up containing {3, 2, 3, 2, 3} instead of {1, 2, 3, 2, 3}.

  parent reply	other threads:[~2019-09-27 11:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19 20:28 François Dumont
2019-09-20  5:08 ` François Dumont
2019-09-25 20:40   ` François Dumont
2019-09-27 11:24   ` Jonathan Wakely [this message]
2019-10-01 20:05     ` François Dumont
2019-10-10 20:03       ` Jonathan Wakely
2019-10-16 20:22         ` François Dumont
2019-09-27 12:11 ` Jonathan Wakely
2019-09-27 16:24   ` François Dumont
2019-09-27 16:45     ` Jonathan Wakely
2019-09-28 21:12       ` [PATCH] Fix algo constexpr tests in Debug mode François Dumont
2019-09-30  9:03         ` Jonathan Wakely
2019-09-30 20:21           ` François Dumont
2019-10-01 11:21             ` Jonathan Wakely
2019-10-23 15:26         ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190927112424.GV9487@redhat.com \
    --to=jwakely@redhat.com \
    --cc=frs.dumont@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).