220 35108 <3446274.dRsjijLxpX@tjmaciei-mobl1> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Marking more std::string_view members noexcept
Date: Wed, 25 Oct 2017 20:04:40 -0700
Lines: 70
Approved: news@gmane.org
Message-ID: <3446274.dRsjijLxpX@tjmaciei-mobl1>
References: <3d03cd7d-2177-98fd-408d-f74b1f6a8552@gmail.com> <5005582.pCRZNEiGFO@tjmaciei-mobl1> <CAGg_6+M1gvNh82YX6x4Nr3=rFSPW973nmumTF0SkyMJ7c2Yoew@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: blaine.gmane.org 1508987091 30757 195.159.176.226 (26 Oct 2017 03:04:51 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 26 Oct 2017 03:04:51 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBTFBYXHQKGQEPLR4BEQ@isocpp.org Thu Oct 26 05:04:44 2017
Return-path: <std-proposals+bncBCB4TK757YBRBTFBYXHQKGQEPLR4BEQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f197.google.com ([209.85.128.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRBTFBYXHQKGQEPLR4BEQ@isocpp.org>)
	id 1e7YTG-0006YG-GN
	for gclcip-std-proposals@m.gmane.org; Thu, 26 Oct 2017 05:04:38 +0200
Original-Received: by mail-wr0-f197.google.com with SMTP id p96sf896707wrb.12
        for <gclcip-std-proposals@m.gmane.org>; Wed, 25 Oct 2017 20:04:46 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1508987085; cv=pass;
        d=google.com; s=arc-20160816;
        b=Q0FovddJ2MaD46LzAhHjiqJd1+R77lUteihzatQD+az6RWPNSgT/uUQXTwkxk83Rsr
         d8PbL5uPLoyRGWHKu8vexfhN9xrIJAMMt4+XdLsQ8MFtJdSv55JUPoxPOqJlmbMv4Nx+
         v0YbhmRJWzN1gAj/orxKs3U5SWJWkqyfJ57WDIe9xQ6As+Rwojn9mVBLcrIDnGRcX66x
         mYSojA/05PVJCnyktkGWI8SlNdbulV3ULKkXXaA3vFN1x/iizOaA2PBWwAComG9kOnHG
         ZL0CRPnhkm2nym8teKtOYLsmqKOVm934dH+T6ciJmBMJ29n9S6U59LM7uJxCjCsDWcgB
         kDIg==
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:mime-version:references
         :in-reply-to:message-id:date:subject:to:from
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=iiaLkSpxtx3a7ADDWktmQywQz0o3whtytpZtyk+/U/Q=;
        b=JldyDyQKD40plAoBryZgpZMp/1VXt55WipD1gPeojXe8jgzI+Q+CIjXfwMFBonVgtB
         9+K7zcPqL4qi1c/hMcgH6+ecpwRiExYqrPAJgU/ieY+hdwP/E4sRtxjNMoHA5fkE2Qvf
         BGA79PUAcMMtIRrbVuWfs1+GrjCqnncqV0KS4xQFfV05F4/KvcWcqU8AuX2fmi0JGKYB
         clDRbJtd+xGmA8v7IUWOBsa8XpwTPVg4JHlG6gfILPfIJrU6bGp01Qj8/WGiWEMQTNTn
         aD4yWNWezo+e2XnEn9PfuqC3oNZevHRkPBUtTVdnzu1dJSTfsOnsELjsF0NqxfdcW8w1
         tkww==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3 as permitted sender) smtp.mailfrom=thiago@macieira.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:to:subject:date:message-id:in-reply-to:references:mime-version
         :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=iiaLkSpxtx3a7ADDWktmQywQz0o3whtytpZtyk+/U/Q=;
        b=y7j53lyfGPWhRzoDwm4y9kUpcG2gf8tq3bLYEGWP+j9RqUGhIJlWAX7JRw715WdHGi
         /Y/c2hwOTDWckrgCoa+9qat+aT+IRFrKz14WS/w3Ef3/rGNlXtmbmMuO2ws/YWsZwxbD
         MunyYeEdjYwNSmlI37t8tp0lk3I0UHXArm42RKzMYZgIsd0iHp8NSwmSQ6oc2O4oXx1M
         4V5+FTT4B+JZ6JSMD+9bqSFM94nH7MVgfAW6Kc1/77OD43x/sos7WKjTpaOmYus/s+N3
         j5Ar/sNE9QJutXPCVYJrUUmpIhGiYin+NGP1DC8B2Rglnhstb0gJPJgrrVkhu/BTfQFy
         E/ew==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references:mime-version: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=iiaLkSpxtx3a7ADDWktmQywQz0o3whtytpZtyk+/U/Q=;
        b=lrZKFxn/llTF+GsXmQYOfmwNwvfZxVHfwVLfudyRUQYbv80yHHaWCj109tgEOZZdmA
         LpV35zEFKkmVKtdB4zPoGAK7Xi8Nu3eusYpzQivM+2Tm0jWfz/OAIfgmXZcHfQq1VYW+
         qFLCiQdH5/LIxcTGDxdejvwnyc1HeVX38FfwB0JZ0T7N47s6FMw751NgyWFw0GTq8V53
         vMaUw3tpHRCvBSLQLk1/F037sxFlQSbciQt8Sre32gAELgjCSHQ5LaStndpXVfOWDOaO
         dG3Ggb0DCduz0aFPY2bk3aMDfOvoJHGCQwppNTdZInumMUE6pjbdz2dAbrqr7/cOcdp5
         CefQ==
X-Gm-Message-State: AMCzsaVnmNKXFz2ShqPi8kDeAkiF6nniF6DGxrzhIAL8E6BBIM0r1WM5
	GOD7YZ1OinEPx8MYRK8K21e6AQ==
X-Google-Smtp-Source: ABhQp+QU6HERgWXYlj31N/okZceoUy3fa5VkMMvc7Vk5NZV225TLItE/DhFlLOO5v4IcBpQ1Z6rqUw==
X-Received: by 10.28.229.139 with SMTP id c133mr28938wmh.13.1508987085670;
        Wed, 25 Oct 2017 20:04:45 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.111.140 with SMTP id c12ls1141341wmi.5.gmail; Wed, 25 Oct
 2017 20:04:44 -0700 (PDT)
X-Received: by 10.28.203.136 with SMTP id b130mr248705wmg.105.1508987084584;
        Wed, 25 Oct 2017 20:04:44 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1508987084; cv=none;
        d=google.com; s=arc-20160816;
        b=aguMsKccDb57KHtunCE8vD811xPXG85dVTp5NLBBIweHcwah+yLKgtvhV4Cdpov1QK
         osHhWPpGFtFQ5Z3a+8RrOhKZpiMvO0okUzmglEsFfDCeztitdIFzke4VXZyGiVPE5Lhi
         nf8hf4KpiOd5nfkZn4pRVqiQs+P6BxX95R/FmSmYWWTkNTRvKMNKBJ50ncoaJLvPPuFU
         RXuEF19cWTnLPtSHxvkTGli+5fmEMu/Ck4g2T17X+w2Un/VFVMyo26kPfv5ajtI9/WeG
         jSRTgxLI0lN6VgVJVaJLBykw18botqsp9eZ6D6lgZuKLXt6gYOks8+aIC/a+JGeTVe6W
         fKEQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:to:from:arc-authentication-results;
        bh=ym1+G7uW9ybbT/GGGNHwl1oAWy9fc0o5hXjNekjcxXA=;
        b=vr5UxkVPAF7b5oorbNfSgdYGbNVKrExBYQGBWjtYblviyUV/UuCrbxkHuJATMs9AhK
         cSA8d/Ztuq9uD3vQQMGhxhBoME2IyCGlxuiKjYOKVUmCAENf5Gk+jnUTQHkDfnJOp8yA
         JWfAGjePew6MsugM0/GHV3Ywpt7uiLvnKKv9/bxEgGMpYrAOjKfMeDXSVdxNFwMriJJv
         rTffGe4Kg5uuloibbW+KmRrPdaM0En9kBRsY51+iOvOsbvRi2gVUrWZrhTs/aShfcHui
         FMDPbbOpfhxXLu3gK/c1Tx+heD5iTcx4qqOHXlJuXYxsCQtdLlySyMScoI+Ebc987Tj+
         WtpQ==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3 as permitted sender) smtp.mailfrom=thiago@macieira.org
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [2a01:4f8:d13:f81:21c:14ff:fe01:12a3])
        by mx.google.com with ESMTP id o1si255213wmf.41.2017.10.25.20.04.44
        for <std-proposals@isocpp.org>;
        Wed, 25 Oct 2017 20:04:44 -0700 (PDT)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3 as permitted sender) client-ip=2a01:4f8:d13:f81:21c:14ff:fe01:12a3;
Original-Received: from tjmaciei-mobl1.localnet (unknown [IPv6:2601:1c0:4501:5f9f:d45e:bf18:2219:b394])
	by gondolin.macieira.info (Postfix) with ESMTPSA id 1F24111B5A6
	for <std-proposals@isocpp.org>; Wed, 25 Oct 2017 20:04:44 -0700 (PDT)
In-Reply-To: <CAGg_6+M1gvNh82YX6x4Nr3=rFSPW973nmumTF0SkyMJ7c2Yoew@mail.gmail.com>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3
 as permitted sender) smtp.mailfrom=thiago@macieira.org
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:35108
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35108>

On Wednesday, 25 October 2017 19:30:21 PDT Nevin Liber wrote:
> > QStringView has both a pointer and an array constructor. That means:
> >         const char16_t str[] = u"Hello\0World";
> >         
> >         QStringView(str).size() == 11   // constexpr
> >         QStringView(+str).size() == 5   // not constexpr
> 
> I'm not sure what constexpr has to do with it.  Isn't it array vs. pointer
> that matters?

Just a dig at the inability to overload on constexprness.

Calculating the length of char16_t(&)[N] is easy: N - 1.

Calculating the length of char16_t* can't be done in a constexpr way.

> It also means
> 
> QStringView(b ? u"Hello\0World" : u"Howdy\0World") has subtly different
> behavior than QStringView(b ? u"Hello\0World" : u"Goodbye\0World"), doesn't
> it?

Uh... I don't know. godbolting to the rescue...

Why does this call the pointer version?
template <unsigned N> void f(const char (&)[N]);
void f(const char *);

void g(bool b)
{
	const char str[] = "World";
	f(str);
}

> > If we had added the constructor at the moment the class was introduced,
> > there
> > would have been no legacy to deal with. Now there will be, so it needs to
> > be
> > done with great care.
> 
> Again, I think matching an array is the wrong solution to the question of
> "is this a string literal"?

Indeed.

> A better solution might be a magic type that, in template contexts, matches
> better than an array but easily decays to an array.  OTOH, it might not be
> (I haven't really thought about it much).  And it still wouldn't address
> the ternary operator problem I mentioned above.

libstdc++ has a GCC-specific solution for string_view: __builtin_constant_p. 
Using that, they can determine whether it is a string literal and they can 
even do a constexpr strlen() for those. They do stop at a null, but that's by 
design.

See the tricks here:

https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/
char_traits.h#L220-L252

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

-- 
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/3446274.dRsjijLxpX%40tjmaciei-mobl1.

.
