220 30402 <CACGiwhG2gei5=k1tO+ZVkMjoFSMyEVXwetwBKtKXQRqAXV8mgg@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: "D. B." <db0451@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: P0298: A byte type definition: with undefined
 pointer arithmetic?
Date: Sat, 7 Jan 2017 20:03:53 +0000
Lines: 100
Approved: news@gmane.org
Message-ID: <CACGiwhG2gei5=k1tO+ZVkMjoFSMyEVXwetwBKtKXQRqAXV8mgg@mail.gmail.com>
References: <e21a1901-1ed5-5795-6244-dd70c4d08adf@f2.dion.ne.jp> <b7eda119-bc5d-4940-b359-45088e6f4d3e@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=f403045eaca849f7c4054586a22d
X-Trace: blaine.gmane.org 1483819442 11947 195.159.176.226 (7 Jan 2017 20:04:02 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 7 Jan 2017 20:04:02 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCWNZ4ECS4GBBKUTYXBQKGQEM5EM3CA@isocpp.org Sat Jan 07 21:03:57 2017
Return-path: <std-proposals+bncBCWNZ4ECS4GBBKUTYXBQKGQEM5EM3CA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wj0-f198.google.com ([209.85.210.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCWNZ4ECS4GBBKUTYXBQKGQEM5EM3CA@isocpp.org>)
	id 1cPxDT-0001tv-EK
	for gclcip-std-proposals@m.gmane.org; Sat, 07 Jan 2017 21:03:51 +0100
Original-Received: by mail-wj0-f198.google.com with SMTP id n3sf75138421wjy.6
        for <gclcip-std-proposals@m.gmane.org>; Sat, 07 Jan 2017 12:03:55 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=CPVrujBV+YOVHD2GxBwoaG2nNXRPHN0qVmtlz8DOmRE=;
        b=beF2xQYQN+uJM1JxggvdxLumupl1EYmrpNcfkXh/X8cfU7K7LReEzHA1BwdqWhVGEq
         FrIG+XENMpcmz+gn3pe2NbOOW2G0mlVe+p0opjddUvWDMT1BYfT5I5DAGu4mNy9DML09
         f3YXxFDYbtdvbPLgJGzn2BRFUacH/+p68xpJnCRqxoVsyOpoHrTX0tHFZB7+47HA0+A3
         82wpRJ9X7N2NhMSifeQ7fTyYrqn+TlqreIxTrDqfe0Vezsgne1/ZSYuaM+f8160fMg2i
         P9TF1n50zk1QUnV8LniN+uCh9hRx2gH3tMo6jRqppaoQIuwUp5h8GLEWoHCz6vMRXKn2
         mdQA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=CPVrujBV+YOVHD2GxBwoaG2nNXRPHN0qVmtlz8DOmRE=;
        b=LqcC8y/kY76yyrgcwQHAFcoi7wcfYICwoHpibHBhgiPOzIf5B5cWZomJOnJvbVJjTo
         d41O4XPjrhHtRoQvV72+uwZp7aaJ25oAeFG8qQsYj5c7y1XPRjJpWCLVw7yXVa3VSZqm
         gdjZIUC9EbDSkjI19QMbusn4BNaZA9EG3uLX3HoocqupYiM4KSbCsQ76LSgrxdg3FBbL
         rvhJ/GyL5MaeL3UzPfMT8toL9Qx5j2fpv81/2LloZmu0oDATOOX4gtER7KYOXMtzziFQ
         PwOTXptpWzTMT121BrtAvzHUa1MPG2LhismFDF8yl1+cIqCih58CBFXYEZ6/NLoeCVvG
         AL5Q==
X-Gm-Message-State: AIkVDXIovS3/OMgqDnY0TBpWWZAy3MVnx95Nm1Jz5+FcIOTx8UZKRW/sR6u1njBipSkJvQ==
X-Received: by 10.28.130.69 with SMTP id e66mr80743wmd.15.1483819435560;
        Sat, 07 Jan 2017 12:03:55 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.140.6 with SMTP id o6ls638336wmd.7.canary-gmail; Sat, 07
 Jan 2017 12:03:54 -0800 (PST)
X-Received: by 10.223.150.34 with SMTP id b31mr6030757wra.196.1483819434700;
        Sat, 07 Jan 2017 12:03:54 -0800 (PST)
Original-Received: from mail-wm0-x22a.google.com (mail-wm0-x22a.google.com. [2a00:1450:400c:c09::22a])
        by mx.google.com with ESMTPS id dk9si68239794wjb.198.2017.01.07.12.03.54
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 07 Jan 2017 12:03:54 -0800 (PST)
Received-SPF: pass (google.com: domain of db0451@gmail.com designates 2a00:1450:400c:c09::22a as permitted sender) client-ip=2a00:1450:400c:c09::22a;
Original-Received: by mail-wm0-x22a.google.com with SMTP id t79so71644717wmt.0
        for <std-proposals@isocpp.org>; Sat, 07 Jan 2017 12:03:54 -0800 (PST)
X-Received: by 10.223.178.9 with SMTP id u9mr6170328wra.110.1483819434242;
 Sat, 07 Jan 2017 12:03:54 -0800 (PST)
Original-Received: by 10.28.144.66 with HTTP; Sat, 7 Jan 2017 12:03:53 -0800 (PST)
In-Reply-To: <b7eda119-bc5d-4940-b359-45088e6f4d3e@isocpp.org>
X-Original-Sender: db0451@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of db0451@gmail.com
 designates 2a00:1450:400c:c09::22a as permitted sender) smtp.mailfrom=db0451@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:30402
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30402>

--f403045eaca849f7c4054586a22d
Content-Type: text/plain; charset=UTF-8

On Sat, Jan 7, 2017 at 7:52 PM, Chris Hallock <christopherhallock@gmail.com>
wrote:

> I, for one, would be shocked if the Committee (or anyone, really) actually
> wants byte-oriented pointer arithmetic within objects to be undefined. I
> strongly anticipate that CWG will accept issue 1701 as a defect and make it
> well-defined.
>

I hope you're right.



> Remember, we're not really talking about the byte accesses themselves;
> such aliasing is already well-defined for char and unsigned char. It is
> only the charPtr + i (or charPtr[i]) expression that is currently
> undefined, and that expression can be awkwardly worked around anyway on
> some platforms (e.g., cast to integer, add, cast back to pointer).
>

Oh, sure, on most platforms/compilers, even the non-workaround syntax just
works, because the compilers don't go to lengths to maliciously subvert
people's intuition. That doesn't make it well-defined per the IS.

In fact, I'm pretty sure that what you said still isn't valid. It's not the
arithmetic that's the problem: it's the fact that it's performed in such a
way as to generate a final pointer that doesn't point into the same
contiguous array as the original source pointer (because a "sequence" of
unsigned char is not an array, formally). By the same token, subtracting or
comparing pointers within such a "sequence" is not valid. See:
https://www.securecoding.cert.org/confluence/display/c/ARR36-C.+Do+not+subtract+or+compare+two+pointers+that+do+not+refer+to+the+same+array
These all seem like adjacent facets of the same issue to me.

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhG2gei5%3Dk1tO%2BZVkMjoFSMyEVXwetwBKtKXQRqAXV8mgg%40mail.gmail.com.

--f403045eaca849f7c4054586a22d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
at, Jan 7, 2017 at 7:52 PM, Chris Hallock <span dir=3D"ltr">&lt;<a target=
=3D"_blank" href=3D"mailto:christopherhallock@gmail.com">christopherhallock=
@gmail.com</a>&gt;</span> wrote:<br><blockquote style=3D"margin:0px 0px 0px=
 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class=3D"gm=
ail_quote"><div dir=3D"ltr">I, for one, would be shocked if the Committee (=
or anyone, really) actually wants byte-oriented pointer arithmetic within o=
bjects to be undefined. I strongly anticipate that CWG will accept issue 17=
01 as a defect and make it well-defined.</div></blockquote><div><br></div><=
div>I hope you&#39;re right.<br><br></div><div>=C2=A0</div><blockquote styl=
e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin=
g-left:1ex" class=3D"gmail_quote"><div dir=3D"ltr">Remember, we&#39;re not =
really talking about the byte accesses themselves; such aliasing is already=
 well-defined for <span style=3D"font-family:courier new,monospace">char</s=
pan> and <span style=3D"font-family:courier new,monospace">unsigned char</s=
pan>. It is only the <span style=3D"font-family:courier new,monospace">char=
Ptr + i</span> (or <span style=3D"font-family:courier new,monospace">charPt=
r[i]</span>) expression that is currently undefined, and that expression ca=
n be awkwardly worked around anyway on some platforms (e.g., cast to intege=
r, add, cast back to pointer).<br></div></blockquote><div><br></div><div>Oh=
, sure, on most platforms/compilers, even the non-workaround syntax just wo=
rks, because the compilers don&#39;t go to lengths to maliciously subvert p=
eople&#39;s intuition. That doesn&#39;t make it well-defined per the IS.<br=
><br></div><div>In fact, I&#39;m pretty sure that what you said still isn&#=
39;t valid. It&#39;s not the arithmetic that&#39;s the problem: it&#39;s th=
e fact that it&#39;s performed in such a way as to generate a final pointer=
 that doesn&#39;t point into the same contiguous array as the original sour=
ce pointer (because a &quot;sequence&quot; of unsigned char is not an array=
, formally). By the same token, subtracting or comparing pointers within su=
ch a &quot;sequence&quot; is not valid. See:=C2=A0 <a href=3D"https://www.s=
ecurecoding.cert.org/confluence/display/c/ARR36-C.+Do+not+subtract+or+compa=
re+two+pointers+that+do+not+refer+to+the+same+array">https://www.securecodi=
ng.cert.org/confluence/display/c/ARR36-C.+Do+not+subtract+or+compare+two+po=
inters+that+do+not+refer+to+the+same+array</a> These all seem like adjacent=
 facets of the same issue to me.<br></div></div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CACGiwhG2gei5%3Dk1tO%2BZVkMjoFSMyEVXw=
etwBKtKXQRqAXV8mgg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhG2gei5=
%3Dk1tO%2BZVkMjoFSMyEVXwetwBKtKXQRqAXV8mgg%40mail.gmail.com</a>.<br />

--f403045eaca849f7c4054586a22d--

.
