public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Christopher Jefferson <chris@bubblescope.net>
Cc: "François Dumont" <frs.dumont@gmail.com>,
	"libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: vector lightweight debug mode
Date: Sat, 19 Sep 2015 09:12:00 -0000	[thread overview]
Message-ID: <CAH6eHdSOs8wk3QkpKr4EdZFHLRA2ddEP1paxWb9GSu8AxXtXJw@mail.gmail.com> (raw)
In-Reply-To: <CA+jCFLuiSYx02OH8UMubsOikPeTMR9sfukPESs1ureQu0WX0+Q@mail.gmail.com>

On 17 September 2015 at 21:52, Christopher Jefferson
<chris@bubblescope.net> wrote:
> ---------- Forwarded message ----------
> From: Christopher Jefferson <chris@bubblescope.net>
> Date: 17 September 2015 at 18:59
> Subject: Re: vector lightweight debug mode
> To: Jonathan Wakely <jwakely@redhat.com>
>
>
> On 16 September 2015 at 21:29, Jonathan Wakely <jwakely@redhat.com> wrote:
>> On 16/09/15 21:37 +0200, François Dumont wrote:
>>
>>>>> @@ -1051,6 +1071,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
>>>>>       iterator
>>>>>       insert(const_iterator __position, size_type __n, const
>>>>> value_type& __x)
>>>>>       {
>>>>> +    __glibcxx_assert(__position >= cbegin() && __position <= cend());
>>>>>     difference_type __offset = __position - cbegin();
>>>>>     _M_fill_insert(begin() + __offset, __n, __x);
>>>>>     return begin() + __offset;
>>>>
>>>>
>>>> This is undefined behaviour, so I'd rather not add this check (I know
>>>> it's on the google branch, but it's still undefined behaviour).
>>>
>>>
>>> Why ? Because of the >= operator usage ? Is the attached patch better ?
>>> < and == operators are well defined for a random access iterator, no ?
>>
>>
>> No, because it is undefined to compare iterators that belong to
>> different containers, or to compare pointers that point to different
>> arrays.
>
> While that's true, on the other hand it's defined behaviour when the
> assert passes, and in the case where the thing it's trying to check
> fails, we are off into undefined-land anyway.
>
> A defined check would be to check if __offset is < 0 or > size(). Once
> again if it's false we are undefined, but the assert line itself is
> then defined behaviour.

That's a good point, but it still means an optimiser could remove the
checks, because it is impossible for them to fail in a correct
program.

That would be no worse than not having the checks at all, but it could
make them unreliable.

  reply	other threads:[~2015-09-19  9:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-14 18:30 François Dumont
2015-09-14 19:55 ` Jonathan Wakely
2015-09-16 19:43   ` François Dumont
2015-09-16 20:53     ` Jonathan Wakely
     [not found]       ` <CA+jCFLueUi0Zo4m2D-scXNG5JLVSObKbJgXWaQRJrQ+notbXzg@mail.gmail.com>
2015-09-17 21:14         ` Fwd: " Christopher Jefferson
2015-09-19  9:12           ` Jonathan Wakely [this message]
2015-09-19  9:09       ` François Dumont
2015-09-19  9:48         ` Jonathan Wakely
2015-09-19 12:00           ` Jonathan Wakely
2015-10-07 19:38             ` François Dumont
2015-10-07 20:09               ` Jonathan Wakely
2015-10-12 19:43                 ` François Dumont
2015-11-15 21:12                   ` François Dumont
2015-11-16 10:29                     ` Jonathan Wakely
2015-11-17 19:49                       ` François Dumont
2015-11-18 12:27                         ` Jonathan Wakely
2015-11-18 12:34                           ` Jonathan Wakely
2015-11-19 21:17                           ` François Dumont

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=CAH6eHdSOs8wk3QkpKr4EdZFHLRA2ddEP1paxWb9GSu8AxXtXJw@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=chris@bubblescope.net \
    --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).