220 28424 <2b8591ee-3a1e-4a41-8c14-221bdc5cd1e4@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Marking more std::string_view members noexcept
Date: Tue, 27 Sep 2016 13:42:02 -0700 (PDT)
Lines: 167
Approved: news@gmane.org
Message-ID: <2b8591ee-3a1e-4a41-8c14-221bdc5cd1e4@isocpp.org>
References: <3d03cd7d-2177-98fd-408d-f74b1f6a8552@gmail.com>
 <CAGNvRgBSk47UXuzh_jm_Yr2pBCM5NYSZ8kqVjwLyWsm-4r6ozw@mail.gmail.com>
 <af89c375-0437-4092-cfc7-d93eafbf969e@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1021_1942696835.1475008922846"
X-Trace: blaine.gmane.org 1475008938 23786 195.159.176.226 (27 Sep 2016 20:42:18 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 27 Sep 2016 20:42:18 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBG5TVO7QKGQE7SO4IUY@isocpp.org Tue Sep 27 22:42:13 2016
Return-path: <std-proposals+bncBCEKFTV6ZUMBBG5TVO7QKGQE7SO4IUY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-it0-f72.google.com ([209.85.214.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBG5TVO7QKGQE7SO4IUY@isocpp.org>)
	id 1bozCY-00055J-Ci
	for gclcip-std-proposals@m.gmane.org; Tue, 27 Sep 2016 22:42:06 +0200
Original-Received: by mail-it0-f72.google.com with SMTP id j69sf58334904itb.1
        for <gclcip-std-proposals@m.gmane.org>; Tue, 27 Sep 2016 13:42:08 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=uTCUULK0/dg3JUfMgxLu5wkb5l7IDiLmfNMLgzEdNzY=;
        b=ASXN5ml82t3t60v3rJXnNCqdIFixhOnE8YqweYAI7CRfTQwbWNorS6bX/DnN10/sWG
         WKbEjHJWSAveHL4DhkpY0ssnFMywDI0tDqWOaIdeZrPbROQr8gw+giZnKZnoWnsfc6zn
         1VoO5/HcUuR4v2VyK4/Rb80kXsmDzHzJKOlhkaIdmuSC9hu62DO/ChCcSGfpqQn4YOsq
         t/mnd6MjDly1VXG9BPeQrZBJW7KR6ZdO4KzYdVqs856EyPUjcu6aVE48CTUaEE0QSGys
         gELakXXOUSHcmN5XomtnKfVUqXlX7RBHaZGQZhsbIxxdViXemKgrOquVmfE/XAXz8Eka
         H8XA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=uTCUULK0/dg3JUfMgxLu5wkb5l7IDiLmfNMLgzEdNzY=;
        b=t00YtrPQlWhi5sWMijCo8wjnw8DtM5siVzEDvl8V/Vb0ZXTwhyhyTVD+lODba6ySBF
         0+o2bNpv44mQ7s4BUZDt7P8Wa5Ll+zRpwrng+iZLeJH1z9RIx0W839V75LYoiX3e5qCf
         BimaBt1eG1lkir87zfsXhqikxf/8BSbwpZS32KaGCNFwmD/56ABJ+9vj1JZxydwzlqeU
         585OFCGQ1l64dwPFNInIudtZKw7MGs3bqYVYMA8VJC5Nyj5LZFNWsTwxwCgCYtsTxf3f
         5hyNgex629IEftO77b2mWD7ePUz189Rm9WjBnfGu6nnQDhaNrkmpWEkmgpsgXXdXvONN
         B1Qg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=uTCUULK0/dg3JUfMgxLu5wkb5l7IDiLmfNMLgzEdNzY=;
        b=Nmo+hcRXDVAGtT2qWo9m2dMEMjzBVrdUGxYwq2eWsF6+JWwAaK0MRmjTsxTI3Ci7fg
         VW+VH4r+mjqmUpDi2T7LZCjjltM0XWCVIO594KxTwRZeaS4you7AG3vCygQpwQPi8onM
         2gNZZgrbDj7NUZ8ww90XgcrrDynJPMAX8JIMbrn4UqkPjWZM2llb/mi5dSB6yZIYvBjT
         eJY8u4RbJKhs3b9a21DjhQPGiwnLKFS8nc25dBer+HSn6iUGay3ngbWq55ejy+MZa2K4
         R+hjABeKVlA4Gn3vxMOrvhshD9TEaUR5u+qQHs3jPTaalS4OL8jTdsW3yQUGwJT27Vyj
         2Gow==
X-Gm-Message-State: AA6/9Rk8iAeBpCsopZR7OIeAc6Ykiia6R5LoNKsAFxTsRl9oV3zYKACoojg0t9mXQ+5K2Q==
X-Received: by 10.157.8.202 with SMTP id 68mr7254859otf.11.1475008927885;
        Tue, 27 Sep 2016 13:42:07 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.69.204 with SMTP id c73ls3507848itd.22.gmail; Tue, 27 Sep
 2016 13:42:03 -0700 (PDT)
X-Received: by 10.36.124.22 with SMTP id a22mr345108itd.4.1475008923776;
        Tue, 27 Sep 2016 13:42:03 -0700 (PDT)
In-Reply-To: <af89c375-0437-4092-cfc7-d93eafbf969e@gmail.com>
X-Original-Sender: jmckesson@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:28424
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/28424>

------=_Part_1021_1942696835.1475008922846
Content-Type: multipart/alternative; 
	boundary="----=_Part_1022_1898984703.1475008922847"

------=_Part_1022_1898984703.1475008922847
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Tuesday, September 27, 2016 at 2:24:48 PM UTC-4, Andrey Semashev wrote:
>
> On 09/27/16 20:47, Daniel Kr=C3=BCgler wrote:=20
> > 2016-09-27 14:21 GMT+02:00 Andrey Semashev <andrey....@gmail.com=20
> <javascript:>>:=20
> >> Hi,=20
> >>=20
> >> I'm looking at string_view interface definition in N4606 and wondering=
=20
> why=20
> >> so many members are not marked noexcept? For example, these=20
> constructors:=20
> >>=20
> >>   constexpr basic_string_view(const charT* str);=20
> >>   constexpr basic_string_view(const charT* str, size_type len);=20
> >>=20
> >> Assuming that the input string is not a constant expression, the first=
=20
> >> constructor would call an equivalent of strlen(str), which in 99% is a=
=20
> >> no-throw operation. Why not mark it=20
> >> "noexcept(noexcept(traits::length(str))"? The second constructor does=
=20
> not=20
> >> even need that and could be simply noexcept.=20
> >>=20
> >> I'm most interested in constructors, but other members like operator[]=
,=20
> >> front(), back(), substr(), compare() also don't seem to need to ever=
=20
> throw,=20
> >> yet they are not marked noexcept.=20
> >>=20
> >> Is there a reason for these omissions?=20
> >=20
> > This is so, because these functions have a narrow contract. The=20
> > current guideline for LWG was described by this proposal:=20
> >=20
> > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3279.pdf=20
>
> I see. Still, it feels wrong that functions that you never expect to=20
> throw are not marked noexcept. When you write non-throwing code you=20
> would look at the functions your code calls and not seeing noexcept=20
> there immediately throws a red flag.
>

I believe the point is that it *shouldn't* "throw a red flag". This is a=20
matter of simple practicality.

C API functions cannot throw exceptions, but they equally are incapable of=
=20
being marked `noexcept`. C++ libraries written before C++11 will not have=
=20
non-throwing functions marked `noexcept`. And many C++ libraries even=20
post-11 don't rigidly mark every non-throwing function as `noexcept`.

At the end of the day, C++ programmers cannot in general assume that every=
=20
function not marked `noexcept` is a throwing function.

--=20
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 e=
mail 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/2b8591ee-3a1e-4a41-8c14-221bdc5cd1e4%40isocpp.or=
g.

------=_Part_1022_1898984703.1475008922847
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, September 27, 2016 at 2:24:48 PM UTC-4=
, Andrey Semashev wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 09/=
27/16 20:47, Daniel Kr=C3=BCgler wrote:
<br>&gt; 2016-09-27 14:21 GMT+02:00 Andrey Semashev &lt;<a href=3D"javascri=
pt:" target=3D"_blank" gdf-obfuscated-mailto=3D"k9hY79sRBQAJ" rel=3D"nofoll=
ow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=
=3D"this.href=3D&#39;javascript:&#39;;return true;">andrey....@gmail.com</a=
>&gt;:
<br>&gt;&gt; Hi,
<br>&gt;&gt;
<br>&gt;&gt; I&#39;m looking at string_view interface definition in N4606 a=
nd wondering why
<br>&gt;&gt; so many members are not marked noexcept? For example, these co=
nstructors:
<br>&gt;&gt;
<br>&gt;&gt; =C2=A0 constexpr basic_string_view(const charT* str);
<br>&gt;&gt; =C2=A0 constexpr basic_string_view(const charT* str, size_type=
 len);
<br>&gt;&gt;
<br>&gt;&gt; Assuming that the input string is not a constant expression, t=
he first
<br>&gt;&gt; constructor would call an equivalent of strlen(str), which in =
99% is a
<br>&gt;&gt; no-throw operation. Why not mark it
<br>&gt;&gt; &quot;noexcept(noexcept(traits::<wbr>length(str))&quot;? The s=
econd constructor does not
<br>&gt;&gt; even need that and could be simply noexcept.
<br>&gt;&gt;
<br>&gt;&gt; I&#39;m most interested in constructors, but other members lik=
e operator[],
<br>&gt;&gt; front(), back(), substr(), compare() also don&#39;t seem to ne=
ed to ever throw,
<br>&gt;&gt; yet they are not marked noexcept.
<br>&gt;&gt;
<br>&gt;&gt; Is there a reason for these omissions?
<br>&gt;
<br>&gt; This is so, because these functions have a narrow contract. The
<br>&gt; current guideline for LWG was described by this proposal:
<br>&gt;
<br>&gt; <a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011=
/n3279.pdf" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&=
#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fs=
c22%2Fwg21%2Fdocs%2Fpapers%2F2011%2Fn3279.pdf\x26sa\x3dD\x26sntz\x3d1\x26us=
g\x3dAFQjCNFtBaj7afJRnnnusmmIo4mfR65Pnw&#39;;return true;" onclick=3D"this.=
href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2F=
jtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2011%2Fn3279.pdf\x26sa\x3dD\x26sntz\x3=
d1\x26usg\x3dAFQjCNFtBaj7afJRnnnusmmIo4mfR65Pnw&#39;;return true;">http://w=
ww.open-std.org/jtc1/<wbr>sc22/wg21/docs/papers/2011/<wbr>n3279.pdf</a>
<br>
<br>I see. Still, it feels wrong that functions that you never expect to=20
<br>throw are not marked noexcept. When you write non-throwing code you=20
<br>would look at the functions your code calls and not seeing noexcept=20
<br>there immediately throws a red flag.<br></blockquote><div><br>I believe=
 the point is that it <i>shouldn&#39;t</i> &quot;throw a red flag&quot;. Th=
is is a matter of simple practicality.<br><br>C API functions cannot throw =
exceptions, but they equally are incapable of being marked `noexcept`. C++ =
libraries written before C++11 will not have non-throwing functions marked =
`noexcept`. And many C++ libraries even post-11 don&#39;t rigidly mark ever=
y non-throwing function as `noexcept`.<br><br>At the end of the day, C++ pr=
ogrammers cannot in general assume that every function not marked `noexcept=
` is a throwing function.<br></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/2b8591ee-3a1e-4a41-8c14-221bdc5cd1e4%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2b8591ee-3a1e-4a41-8c14-221bdc5cd1e4=
%40isocpp.org</a>.<br />

------=_Part_1022_1898984703.1475008922847--

------=_Part_1021_1942696835.1475008922846--

.
