220 35112 <545c118e-8d6d-456b-a640-0e3c0784f583@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: pavel.kryukov@phystech.edu
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Marking more std::string_view members noexcept
Date: Thu, 26 Oct 2017 02:30:45 -0700 (PDT)
Lines: 239
Approved: news@gmane.org
Message-ID: <545c118e-8d6d-456b-a640-0e3c0784f583@isocpp.org>
References: <3d03cd7d-2177-98fd-408d-f74b1f6a8552@gmail.com>
 <5005582.pCRZNEiGFO@tjmaciei-mobl1>
 <CAGg_6+M1gvNh82YX6x4Nr3=rFSPW973nmumTF0SkyMJ7c2Yoew@mail.gmail.com>
 <3446274.dRsjijLxpX@tjmaciei-mobl1>
 <a82f7b048d91673203c75fa04e98f481@kdab.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_235_2019475208.1509010245388"
X-Trace: blaine.gmane.org 1509010266 28610 195.159.176.226 (26 Oct 2017 09:31:06 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 26 Oct 2017 09:31:06 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC3LNQ5G3UMRBRWWY3HQKGQEQWCEDGY@isocpp.org Thu Oct 26 11:31:02 2017
Return-path: <std-proposals+bncBC3LNQ5G3UMRBRWWY3HQKGQEQWCEDGY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk0-f72.google.com ([209.85.213.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC3LNQ5G3UMRBRWWY3HQKGQEQWCEDGY@isocpp.org>)
	id 1e7eUq-0004oL-4e
	for gclcip-std-proposals@m.gmane.org; Thu, 26 Oct 2017 11:30:40 +0200
Original-Received: by mail-vk0-f72.google.com with SMTP id v3sf1244334vkb.20
        for <gclcip-std-proposals@m.gmane.org>; Thu, 26 Oct 2017 02:30:47 -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
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=RDXiLxGx7CcMobdeHsFwOsm5T4RfL6FgCVFWqA5vA20=;
        b=BtoXhr2WWvC7nM9L8w4khfYgaXsFStx5daBkGbhwu6YnKp1PUxCZvJjnKKwfukwdOB
         isFAm6DjVzArD/3NQIoX/NrnAWMKchW9Z0QteZKAEWCuw9MShobOfBZ4TxlKQsZkCXQ+
         vTq/pKc2E8FS7j5G7+/O8bT6t+9hW++hr9YocTECd4JVXuhF/k2I+yEwq4eY3LZL9L6n
         O3coyeGkZ+sXHCNmsUuKY63LrJjFL0s9+wuj1oTFLUcIFDyW590CWLi7Hy2pgc+rmtYx
         QS0FpcmHuMppVQeV2kKPakgpHdvV+muKnnX1LcJH8x1h+OI0+qP0zutaWCQ+0ZPzNhPR
         6FRg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        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=RDXiLxGx7CcMobdeHsFwOsm5T4RfL6FgCVFWqA5vA20=;
        b=GvkAizTbnpJiHPuJaAW3JoUxQjuSfLdgIrzP4BiCFOLO8yb83AKFnCEoTR2kQTTBtU
         xXcqHyzqpcVymewNiA7f4tpcocuTtUpvtk6usqGiqzzX9DcnrAhWWupUalCxZTq3Rslk
         yuUit01wjUY4MWLcRMnFpX/b6FWoogLiFhzimW3ajU6oGvnSqv45re7VnMghfPcFGPv+
         gRI5pY9k6YVHAP3ovsoTLjt6aZEIZ4TLspWUFv5if3bN6YebaU9t3xihBqXwmS80IlpC
         CZSmna8eM6xTHlyQI+nrx9js+hUi0oIdu2mDhmYujsUXFj6AFbbez7ZHpxHdWM/GRaRH
         47jg==
X-Gm-Message-State: AMCzsaUhEkTQHE+3GGxbN+mXri197yeUsoh36hY82Kh0uwjOybqdNr3k
	RM5I2gFNwH6OvOLwTwXXJ6CM/g==
X-Google-Smtp-Source: ABhQp+Ro2ZnLPvIJixe56Splvwxykm43mW0zs8oKX5Mj6ASJNT5K5pxK2gEGiwKObchOaWmBCMAFMw==
X-Received: by 10.176.68.194 with SMTP id n60mr2545418uan.10.1509010247367;
        Thu, 26 Oct 2017 02:30:47 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.31.95.212 with SMTP id t203ls1348779vkb.0.gmail; Thu, 26 Oct
 2017 02:30:45 -0700 (PDT)
X-Received: by 10.31.50.18 with SMTP id y18mr424592vky.6.1509010245813;
        Thu, 26 Oct 2017 02:30:45 -0700 (PDT)
In-Reply-To: <a82f7b048d91673203c75fa04e98f481@kdab.com>
X-Original-Sender: pavel.kryukov@phystech.edu
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:35112
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35112>

------=_Part_235_2019475208.1509010245388
Content-Type: multipart/alternative; 
	boundary="----=_Part_236_1993802447.1509010245388"

------=_Part_236_1993802447.1509010245388
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

> This one still has the precondition that [Char, N) is a valid range. It=
=20
> might not be:=20

>    char bug[512];=20
>    auto s =3D string_view(bug);=20

Should std::string_view have such precondition, isn't it just a wrapper=20
around pointer and size which may dangle?
You may construct a nullptr string_view using argument-less ctor (it is=20
even noexcept) or get a valid string_view from a valid string, but then=20
break it.

auto tmp =3D new std::string("Hello World");
std::string_view sv(tmp.c_str());
delete tmp;

Thanks,
--
Pavel

=D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D0=B3, 26 =D0=BE=D0=BA=D1=82=D1=8F=D0=
=B1=D1=80=D1=8F 2017 =D0=B3., 11:55:14 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=
=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Marc Mutz =D0=BD=D0=B0=D0=BF=D0=
=B8=D1=81=D0=B0=D0=BB:
>
> On 2017-10-26 05:04, Thiago Macieira wrote:=20
> > On Wednesday, 25 October 2017 19:30:21 PDT Nevin Liber wrote:=20
> >> > QStringView has both a pointer and an array constructor. That means:=
=20
> >> >         const char16_t str[] =3D u"Hello\0World";=20
> >> >=20
> >> >         QStringView(str).size() =3D=3D 11   // constexpr=20
> >> >         QStringView(+str).size() =3D=3D 5   // not constexpr=20
> >>=20
> >> I'm not sure what constexpr has to do with it.  Isn't it array vs.=20
> >> pointer=20
> >> that matters?=20
> >=20
> > Just a dig at the inability to overload on constexprness.=20
>
> In QStringView, it's just an optimisation, because...=20
>
> > Calculating the length of char16_t(&)[N] is easy: N - 1.=20
>
> ... this is C++11-constexpr (which we still need to care for, in Qt)=20
> while ...=20
>
> > Calculating the length of char16_t* can't be done in a constexpr way.=
=20
>
> ... is only C++14-constexpr (well, if you want to support reasonably=20
> long strings, otherwise you could come up with a recursive=20
> implementation).=20
>
> We should probably document that the QStringView array ctor has the=20
> precondition that it contains no embedded NULs, but it seems qdoc is too=
=20
> clever for it's own good:=20
> https://doc-snapshots.qt.io/qt5-5.10/qstringview.html doesn't have the=20
> docs for the array ctor.=20
>
> >> It also means=20
> >>=20
> >> QStringView(b ? u"Hello\0World" : u"Howdy\0World") has subtly=20
> >> different=20
> >> behavior than QStringView(b ? u"Hello\0World" : u"Goodbye\0World"),=20
> >> doesn't=20
> >> it?=20
> >=20
> > Uh... I don't know. godbolting to the rescue...=20
> >=20
> > Why does this call the pointer version?=20
> > template <unsigned N> void f(const char (&)[N]);=20
> > void f(const char *);=20
> >=20
> > void g(bool b)=20
> > {=20
> >         const char str[] =3D "World";=20
> >         f(str);=20
> > }=20
>
> Because ordinary functions are preferred over templates. You need=20
> constrained templates to overload on pointer vs. array:=20
> https://www.kdab.com/qstringview-diaries-masters-overloads/ (can't seem=
=20
> to link to a section, C-F for 'third').=20
>
> Thanks,=20
> Marc=20
>
>

--=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/545c118e-8d6d-456b-a640-0e3c0784f583%40isocpp.or=
g.

------=_Part_236_1993802447.1509010245388
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">&gt; This one still has the precondition that [Char, N) is=
 a valid range. It=C2=A0<br>&gt; might not be:=C2=A0<div><br>&gt;=C2=A0 =C2=
=A0 char bug[512];=C2=A0<br>&gt;=C2=A0 =C2=A0 auto s =3D string_view(bug);=
=C2=A0<div><br></div><div>Should std::string_view have such precondition, i=
sn&#39;t it just a wrapper around pointer and size which may dangle?</div><=
div>You may construct a nullptr string_view using argument-less ctor (it is=
 even noexcept) or get a valid string_view from a valid string, but then br=
eak it.</div><div><br></div><div>auto tmp =3D new std::string(&quot;Hello W=
orld&quot;);</div><div>std::string_view sv(tmp.c_str());</div><div>delete t=
mp;</div><div><br></div><div>Thanks,</div><div>--</div><div>Pavel</div><div=
><br>=D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D0=B3, 26 =D0=BE=D0=BA=D1=82=D1=
=8F=D0=B1=D1=80=D1=8F 2017 =D0=B3., 11:55:14 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C=
=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Marc Mutz =D0=BD=D0=B0=D0=
=BF=D0=B8=D1=81=D0=B0=D0=BB:<blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On=
 2017-10-26 05:04, Thiago Macieira wrote:
<br>&gt; On Wednesday, 25 October 2017 19:30:21 PDT Nevin Liber wrote:
<br>&gt;&gt; &gt; QStringView has both a pointer and an array constructor. =
That means:
<br>&gt;&gt; &gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 const char16_t str[] =3D u&qu=
ot;Hello\0World&quot;;
<br>&gt;&gt; &gt;
<br>&gt;&gt; &gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 QStringView(str).size() =3D=
=3D 11 =C2=A0 // constexpr
<br>&gt;&gt; &gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 QStringView(+str).size() =3D=
=3D 5 =C2=A0 // not constexpr
<br>&gt;&gt;=20
<br>&gt;&gt; I&#39;m not sure what constexpr has to do with it. =C2=A0Isn&#=
39;t it array vs.=20
<br>&gt;&gt; pointer
<br>&gt;&gt; that matters?
<br>&gt;=20
<br>&gt; Just a dig at the inability to overload on constexprness.
<br>
<br>In QStringView, it&#39;s just an optimisation, because...
<br>
<br>&gt; Calculating the length of char16_t(&amp;)[N] is easy: N - 1.
<br>
<br>... this is C++11-constexpr (which we still need to care for, in Qt)=20
<br>while ...
<br>
<br>&gt; Calculating the length of char16_t* can&#39;t be done in a constex=
pr way.
<br>
<br>... is only C++14-constexpr (well, if you want to support reasonably=20
<br>long strings, otherwise you could come up with a recursive=20
<br>implementation).
<br>
<br>We should probably document that the QStringView array ctor has the=20
<br>precondition that it contains no embedded NULs, but it seems qdoc is to=
o=20
<br>clever for it&#39;s own good:=20
<br><a href=3D"https://doc-snapshots.qt.io/qt5-5.10/qstringview.html" targe=
t=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;https://www.g=
oogle.com/url?q\x3dhttps%3A%2F%2Fdoc-snapshots.qt.io%2Fqt5-5.10%2Fqstringvi=
ew.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGC3_9RFNqXxNXbggV2rzKniOmWM=
A&#39;;return true;" onclick=3D"this.href=3D&#39;https://www.google.com/url=
?q\x3dhttps%3A%2F%2Fdoc-snapshots.qt.io%2Fqt5-5.10%2Fqstringview.html\x26sa=
\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGC3_9RFNqXxNXbggV2rzKniOmWMA&#39;;return=
 true;">https://doc-snapshots.qt.io/<wbr>qt5-5.10/qstringview.html</a> does=
n&#39;t have the=20
<br>docs for the array ctor.
<br>
<br>&gt;&gt; It also means
<br>&gt;&gt;=20
<br>&gt;&gt; QStringView(b ? u&quot;Hello\0World&quot; : u&quot;Howdy\0Worl=
d&quot;) has subtly=20
<br>&gt;&gt; different
<br>&gt;&gt; behavior than QStringView(b ? u&quot;Hello\0World&quot; : u&qu=
ot;Goodbye\0World&quot;),=20
<br>&gt;&gt; doesn&#39;t
<br>&gt;&gt; it?
<br>&gt;=20
<br>&gt; Uh... I don&#39;t know. godbolting to the rescue...
<br>&gt;=20
<br>&gt; Why does this call the pointer version?
<br>&gt; template &lt;unsigned N&gt; void f(const char (&amp;)[N]);
<br>&gt; void f(const char *);
<br>&gt;=20
<br>&gt; void g(bool b)
<br>&gt; {
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0const char str[] =
=3D &quot;World&quot;;
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0f(str);
<br>&gt; }
<br>
<br>Because ordinary functions are preferred over templates. You need=20
<br>constrained templates to overload on pointer vs. array:=20
<br><a href=3D"https://www.kdab.com/qstringview-diaries-masters-overloads/"=
 target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;https:/=
/www.google.com/url?q\x3dhttps%3A%2F%2Fwww.kdab.com%2Fqstringview-diaries-m=
asters-overloads%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwd-R_i6_H0P57D=
f26OsN74RqcLg&#39;;return true;" onclick=3D"this.href=3D&#39;https://www.go=
ogle.com/url?q\x3dhttps%3A%2F%2Fwww.kdab.com%2Fqstringview-diaries-masters-=
overloads%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwd-R_i6_H0P57Df26OsN7=
4RqcLg&#39;;return true;">https://www.kdab.com/<wbr>qstringview-diaries-mas=
ters-<wbr>overloads/</a> (can&#39;t seem=20
<br>to link to a section, C-F for &#39;third&#39;).
<br>
<br>Thanks,
<br>Marc
<br>
<br></blockquote></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/545c118e-8d6d-456b-a640-0e3c0784f583%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/545c118e-8d6d-456b-a640-0e3c0784f583=
%40isocpp.org</a>.<br />

------=_Part_236_1993802447.1509010245388--

------=_Part_235_2019475208.1509010245388--

.
