220 35114 <e989bea8667eb2c1c36f370e259e00c2@kdab.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Marc Mutz <marc.mutz@kdab.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Marking more std::string_view members noexcept
Date: Thu, 26 Oct 2017 11:55:08 +0200
Organization: KDAB
Lines: 53
Approved: news@gmane.org
Message-ID: <e989bea8667eb2c1c36f370e259e00c2@kdab.com>
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>
 <545c118e-8d6d-456b-a640-0e3c0784f583@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"; format=flowed
X-Trace: blaine.gmane.org 1509011734 27760 195.159.176.226 (26 Oct 2017 09:55:34 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 26 Oct 2017 09:55:34 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCRPXDOU7ECRBBHCY3HQKGQE6WVGTXA@isocpp.org Thu Oct 26 11:55:27 2017
Return-path: <std-proposals+bncBCRPXDOU7ECRBBHCY3HQKGQE6WVGTXA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f198.google.com ([209.85.128.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCRPXDOU7ECRBBHCY3HQKGQE6WVGTXA@isocpp.org>)
	id 1e7esc-0004cj-Fp
	for gclcip-std-proposals@m.gmane.org; Thu, 26 Oct 2017 11:55:14 +0200
Original-Received: by mail-wr0-f198.google.com with SMTP id c42sf1372151wrc.13
        for <gclcip-std-proposals@m.gmane.org>; Thu, 26 Oct 2017 02:55:22 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1509011717; cv=pass;
        d=google.com; s=arc-20160816;
        b=lEHkxW6Dpqo+LW96P31okHH+H9vQiUzHMy715mjuDo+cTiLbKYufjCpZ0wDReIlodG
         QU9YazqGnSQfg+zU6Ee61P3cASTxgxRaZ0UGU7DXHH2ngLo5KsgptJDFLeq5P+2TigO3
         enL933V+7WsiqZLp/tE8Nv/9IiNSDpPmkwPw9y/HD97F8ZKRwbu/5Gi2apwv60fz2wYP
         P6Id2kWcZY4GkJCbhe162PkUWtdaJhI+vQ7qz8guYgt16nGcjmCgB64/WebR/9a25T1W
         V4ivYkYFcS/LlRsKYaT0JiBTa8UXHXROpnK4yWWdIr3gw+IaSgtmSNCF1VsEPsDOeHP6
         TwBQ==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:message-id:references
         :in-reply-to:organization:subject:to:from:date:mime-version
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=JiCYFJv1aRo8ttI3qUD8wwbPpj57F0eiOTvmwggwqF8=;
        b=werQAAPiFo5fSLR/BZfX/RlpPp7K2wHpxah2vArW7UD0ucKXCZgxIyCu19D0/Z7Vlw
         t8WdD/UtToJtnC/rZprlSGO6nOxCHdQunUsHHcLzBHJzDcZpvCP0i/0s46ZuJSzshWCC
         KrLJ1HH0JjPidtCkpgdhDBrf9I80yOEkJxpmaDG5TCssl9nVpbEBNbDxz1HJq6tpbuNy
         SdgnQXm4l0PrsTrWufiK4QjF69eTCIoqJbbaPYkbHhFP5ewCzXjUEyxUCnNiSXfXtXFJ
         OBv5n3ubSr7vIOe3cb8j7DTR9a6P4cPQYa7Gm1UGrmCeFCZSxBQOirk0NkJjV+2QaHz+
         xtgA==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) smtp.mailfrom=marc.mutz@kdab.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:date:from:to:subject:organization:in-reply-to
         :references:message-id:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=JiCYFJv1aRo8ttI3qUD8wwbPpj57F0eiOTvmwggwqF8=;
        b=E28hRFSYGiZM1qwIFoJ+uIt8PI+oucWrxWTXzynqfvPClfX5KApCBDuxcraQsw3I2Q
         pqcRnB2kRXCEhMRDbz2ueScYjTeFhJL/vn01BDthpKor0j61HNTFR/zZ9w95XXO1gNIz
         Lf2/2rKu1Ro2Q0KbN0ObJHcGIo0wvpBfkw9NZJ4xdqhkRzJFhPxnHx7WV1TrAwR/vVhw
         sS5QrQQ8AqO5vsGBH574QfUwBtD2JMtdZ5Go5P52NigFT0p+XrSp4JplXzoJgo4DZGzU
         xQIt+x3HCsPGWkfwHvUY71ehxoiz6WYFSFb5iKBjkharHENCslepLV8PpunGflV7tNRR
         P/Tg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:date:from:to:subject:organization
         :in-reply-to:references:message-id: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=JiCYFJv1aRo8ttI3qUD8wwbPpj57F0eiOTvmwggwqF8=;
        b=CuvWkoA+K9ieUrm8oaxNVY2TunVpfifGE6aq/FEAEpc0iNP6X4rbrQ+YiNR2Sm59xk
         wxIDLVTYMGAk6ZIlMG2PSfDZ8P9aaHFe0mI7l/tjeUgnUI85PJRlOLvo1Y7d82tTbtBm
         WXjaLE7YMGfA2WGWpXFB17fSn4qRz8T1qm6kRCHMUTih+T+JcvIq8S/U2Y5WNMk+rS/E
         aCoR0tIUBh+yrl5oXz327p7EhyNpaFLS9miu/x6QdzqCMg1vCqN9SL/5Oqbh52xVcCDX
         ziK72NHyynxltodHKD/vJafgtVbU+VejvlGbMQXileaoWcz47+X465AnrCqksNqMSovz
         cUuw==
X-Gm-Message-State: AMCzsaXEVOO12eBZo2P4sv7uR3nNCJJv0ASZnX78wMQOMOjzlLe0b1Mg
	cjXpM6CserZbE8vJnKvxlVGjAg==
X-Google-Smtp-Source: ABhQp+T+UMhQ/DpKthZrYK65nvfWTrC5ctyOirewa3kaUnOCQIeFFgtQ7GJcTBHddOCeHZGYMjSzVg==
X-Received: by 10.223.175.196 with SMTP id y4mr498091wrd.30.1509011717123;
        Thu, 26 Oct 2017 02:55:17 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.159.4 with SMTP id i4ls1282395wme.3.gmail; Thu, 26 Oct 2017
 02:55:16 -0700 (PDT)
X-Received: by 10.223.183.7 with SMTP id l7mr4582837wre.139.1509011716290;
        Thu, 26 Oct 2017 02:55:16 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1509011716; cv=none;
        d=google.com; s=arc-20160816;
        b=tLz71j8SGwXQ2ldyh+uUvfiDvaUhEkCAxuVTNGsaaxLtH5pl0OZ+yA50+69x7NLAr5
         SNXveqnm+EYN2NSD8Z+s+9cy4uJXdiUtC+fJADwqfVLPbVEbjw3g8X2LV+MsrokYZu86
         v8gp6pW8KpNgGijoqYURAhCzioEpxIil2CQBSeK+bWg0PfPSgeWP7FQYq/djiD8yD4pz
         s5Pj6q/TlwK0PfelA1RUKRMyqdKCIAUL7LW+6ai3FfGY//IIkbiStHWasI93ftUGJfIJ
         IoI294ZRFbjaJ8XR52DHnL6htxcLbBwdkaU8TBUkZLGGecsqZnTJEmVi9/wHiPhCrUCd
         f8Zg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=message-id:references:in-reply-to:organization:subject:to:from:date
         :content-transfer-encoding:mime-version:arc-authentication-results;
        bh=gLXXeMnYgiA4zcedI9oFLq+EI8rg4qoagm375Qz5PWI=;
        b=krdcolWk3Ss+HYbZth0L1MVttiEo9mNvYj0nvhaMJ2NRsn16gqmevq00O5ViRnVNF3
         tbjihszKmMqAdM6iElwW7AMm0maTZob9Tehfkf5KnTLNwB1cxaKLdC2ZwnzOIL9FFPMe
         LCE2Q0Vrhj+KJ3zm2shFnKUehGIgDZRnQbM+PWzxz5hIgAL5jWwjPkCOYgibYO8cIrl9
         aSp5MLiiafzjrSCBRMudwlH8K86hmah7FDZfe0U8yask9YYrtFdo96wBwJlvjK+8/Wig
         ijioyVN36F7JSQVv2t2cFIHv4U06T7bUX5fbQT8uK5TZ3x4cv0tdxmFYfXS/Uu2imVps
         ZIQg==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) smtp.mailfrom=marc.mutz@kdab.com
Original-Received: from mail.kdab.com (mail.kdab.com. [176.9.126.58])
        by mx.google.com with ESMTPS id o64si686446wmo.121.2017.10.26.02.55.16
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Thu, 26 Oct 2017 02:55:16 -0700 (PDT)
Received-SPF: pass (google.com: domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) client-ip=176.9.126.58;
X-Virus-Scanned: amavisd-new at kdab.com
In-Reply-To: <545c118e-8d6d-456b-a640-0e3c0784f583@isocpp.org>
X-Sender: marc.mutz@kdab.com
X-Original-Sender: marc.mutz@kdab.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) smtp.mailfrom=marc.mutz@kdab.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:35114
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35114>

On 2017-10-26 11:30, pavel.kryukov@phystech.edu wrote:
>> This one still has the precondition that [Char, N) is a valid range.
> It
>> might not be:
> 
>>    char bug[512];
>>    auto s = string_view(bug);
> 
> Should std::string_view have such precondition, isn't it just a
> wrapper around pointer and size which may dangle?

Yes, it should, IMHO. Consider;

    f(std::string); // wide contract: all strings are acceptable
    f(const char *s, size_t n); // narrow contract: [s,n) must be valid 
range
    f(std::string_view); // wide or narrow contract?

By putting the precondition on the string_view ctor, we gain wide 
contracts for any string_view function. This means they can be noexcept, 
and that is much more valuable than having a noexcept string_view ctor 
(which is inline), because string_view-taking functions are often 
out-of-line, so marking them noexcept (where no additional preconditions 
prevent it) actually helps the compiler.

> You may construct a nullptr string_view using argument-less ctor (it
> is even noexcept)

Yes, and?

> or get a valid string_view from a valid string, but
> then break it.
> 
> auto tmp = new std::string("Hello World");
> std::string_view sv(tmp.c_str());
> delete tmp;

Yes, this is a problem. But I'm not sure that it actually can be 
formulated with the term 'precondition'. The closest I can come up with 
is an external class invariant, which is a bit of an oxymoron to start 
with, because classes exist to establish and maintain their invariants.

But it's not really different from std::ref, say.

Thanks,
Marc

-- 
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/e989bea8667eb2c1c36f370e259e00c2%40kdab.com.

.
