220 17239 <273de67b-0d68-42b9-ab94-c69f3f53da79@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Vittorio Romeo <vittorio.romeo.vee@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: noexcept(auto)
Date: Sat, 4 Apr 2015 12:31:51 -0700 (PDT)
Lines: 241
Approved: news@gmane.org
Message-ID: <273de67b-0d68-42b9-ab94-c69f3f53da79@isocpp.org>
References: <1657285.u9ziYB6mWs@tjmaciei-mobl4>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1466_1894749134.1428175911784"
X-Trace: ger.gmane.org 1428175921 28519 80.91.229.3 (4 Apr 2015 19:32:01 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 4 Apr 2015 19:32:01 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCO3NDEYZQHRBKHYQCUQKGQEHHVYMUI@isocpp.org Sat Apr 04 21:31:55 2015
Return-path: <std-proposals+bncBCO3NDEYZQHRBKHYQCUQKGQEHHVYMUI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yk0-f198.google.com ([209.85.160.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCO3NDEYZQHRBKHYQCUQKGQEHHVYMUI@isocpp.org>)
	id 1YeTnO-0003Jk-EP
	for gclcip-std-proposals@m.gmane.org; Sat, 04 Apr 2015 21:31:54 +0200
Original-Received: by ykex7 with SMTP id x7sf941916yke.1
        for <gclcip-std-proposals@m.gmane.org>; Sat, 04 Apr 2015 12:31:53 -0700 (PDT)
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
         :content-type:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=tp/6R36jmZFNSvlV5zU89o5R/FJ8JqCAHGXTUAcxPOk=;
        b=PgYcPgJHZM8OkE5ZmEhl0V8cPmccrM6c+AxZAJ5GOGa7gWshFK74ogKv88+y3cwsxA
         BkbWeyFdc7NILhQUXAyNeScgswaLc+BSCJpSeTAkNLtfKxgvQuZGZjsHPeT2ZnFPenyp
         EO+gB1nUVHz7SZbyqHUyBlmQ/uAoEeNIwu4rQsm4K1IUkFK8zceFswZ05r0XwEM7zNxE
         QMw3qKJZPNSP5/3IsDVFIfpVxg8sHRUmgTz68z2c8yEW/nmCl7CobCWy5XY6OjtES4bD
         ZgH7W76th6aPy8mFF5mllb3DEW1B7AxMKFzmuL8kh9svR7MK7FOw0IYf4z3WSxx3SICs
         ZNNg==
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:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=tp/6R36jmZFNSvlV5zU89o5R/FJ8JqCAHGXTUAcxPOk=;
        b=ZLxeT9UOIcJ4psbuDSGyfhHrZrFRE8uvMqhXStlq7zXsWx6XKMmQLpoCPD7VGvzA/5
         8r0kJU+6aMzgpq8s9dg5KYAUiAPg4+DamBadjJW38bfQlovch2BzNiHK3p0SxhyZ3ZEX
         tG8CHGmJzLObZtuihAoa8mt4gI3Um1fTkc14HlzFnxBSZTLCzUoSrbcLjFm5eMFdQn3t
         +5VupGWl8tSwNwl6KQ3psw+LsNv5W39SXdwy0MzsDpfh51NTDfD9AQgRvH0MY4+cj+Pg
         vMt6iN+RtcBEz5LppmNB1E3DDvxYFBAPMvi2P3ghGser07fvnaKSCXR9fWUYpEoyYA6o
         UoeQ==
X-Gm-Message-State: ALoCoQmQ5kEq1dR8rCiAHidCbfPuPOfx0BS18j+vy9KO7TRd6kerxJ7MxnrKQmHkXANKC8bLrLNV
X-Received: by 10.236.27.52 with SMTP id d40mr9565381yha.13.1428175913174;
        Sat, 04 Apr 2015 12:31:53 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.102.212 with SMTP id w78ls1605218qge.36.gmail; Sat, 04 Apr
 2015 12:31:52 -0700 (PDT)
X-Received: by 10.140.99.44 with SMTP id p41mr94687qge.3.1428175912459;
        Sat, 04 Apr 2015 12:31:52 -0700 (PDT)
In-Reply-To: <1657285.u9ziYB6mWs@tjmaciei-mobl4>
X-Original-Sender: vittorio.romeo.vee@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:17239
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17239>

------=_Part_1466_1894749134.1428175911784
Content-Type: multipart/alternative; 
	boundary="----=_Part_1467_13693775.1428175911784"

------=_Part_1467_13693775.1428175911784
Content-Type: text/plain; charset=UTF-8

I definitely have a lot of occurrences in my code where I repeat the body 
of small functions in the noexcept qualifier. 
Something like this would help a lot.

Would there be any issue in expanding this feature proposal to non-one-line 
functions?

Wouldn't the compiler be able to convert something like:

void func() noexcept(auto)
{
    int a;
    SomeClass b;
    auto c = b + a;
    std::cout << c;
}

to

void func() noexcept
(
    noexcept(int{}) &&
    noexcept(SomeClass{}) &&
    noexcept(b + a) &&
    noexcept(std::cout << c)
)
{
    int a;
    SomeClass b;
    auto c = b + a;
    std::cout << c;
}

?


On Saturday, 4 April 2015 20:50:38 UTC+2, Thiago Macieira wrote:
>
> I find that we're often adding a lot of code in the following pattern: 
>
> T functionName(args) noexcept(noexcept(<block of code>)) 
> { 
>         return <block of code> 
> } 
>
> Where the block of code is repeated. For example, in a commit I've just 
> reviewed: 
>
> template <typename T, int Prealloc1, int Prealloc2> 
> bool operator<(const QVarLengthArray<T, Prealloc1> &lhs, const 
> QVarLengthArray<T, Prealloc2> &rhs) 
>     noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), 
>                                                rhs.begin(), rhs.end()))) 
> { 
>     return std::lexicographical_compare(lhs.begin(), lhs.end(), 
>                                         rhs.begin(), rhs.end()); 
> } 
>
> The first question that comes to mind is why we have to do that? If the 
> compiler can tell that the block of code is noexcept and the function is 
> clearly inline, why do we need to add the noexcept declaration in the 
> first 
> place? 
>
> A good reason for that is that you can't guarantee that the function will 
> always be inline. Binary compatibility aside, a new version of the 
> codebase 
> could de-inline the code, so the declaration should still contain the 
> necessary bits for noexcept. 
>
> So I'd like to propose we add the ability to write "noexcept(auto)" in 
> addition to "noexcept(true)' and "noexcept(false)" to indicate to the 
> compiler 
> that it should calculate whether the body of the inline function is 
> noexcept 
> or not. 
>
> More specifically, to [except.spec]/1, add: 
>         noexcept-specification: 
>                 noexcept ( constant-expression ) 
> +                noexcept (auto) 
>                 noexcept 
>
> Then add a new paragraph after paragraph 1, before paragraph 2, explaining 
> that the "noexcept(auto)" specification may only appear in function 
> definitions 
> and what it is equivalent of. 
>
> Does this seem reasonable? 
> -- 
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org 
>    Software Architect - Intel Open Source Technology Center 
>       PGP/GPG: 0x6EF45358; fingerprint: 
>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358 
>
>

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1467_13693775.1428175911784
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I definitely have a lot of occurrences in my code where I =
repeat the body of small functions in the noexcept qualifier.&nbsp;<br>Some=
thing like this would help a lot.<br><br>Would there be any issue in expand=
ing this feature proposal to non-one-line functions?<br><br>Wouldn't the co=
mpiler be able to convert something like:<br><br>void func() noexcept(auto)=
<br>{<div>&nbsp; &nbsp; int a;<br>&nbsp; &nbsp; SomeClass b;</div><div>&nbs=
p; &nbsp; auto c =3D b + a;<br>&nbsp; &nbsp; std::cout &lt;&lt; c;<br>}<br>=
<br>to<br><br>void func() noexcept</div><div>(</div><div>&nbsp; &nbsp; noex=
cept(int{}) &amp;&amp;</div><div>&nbsp; &nbsp; noexcept(SomeClass{}) &amp;&=
amp;</div><div>&nbsp; &nbsp; noexcept(b + a) &amp;&amp;</div><div>&nbsp; &n=
bsp; noexcept(std::cout &lt;&lt; c)</div><div>)</div><div>{<div>&nbsp; &nbs=
p; int a;<br>&nbsp; &nbsp; SomeClass b;</div><div>&nbsp; &nbsp; auto c =3D =
b + a;<br>&nbsp; &nbsp; std::cout &lt;&lt; c;<br>}<br><br>?<br><br></div><b=
r>On Saturday, 4 April 2015 20:50:38 UTC+2, Thiago Macieira  wrote:<blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;">I find that we're often adding a lot o=
f code in the following pattern:
<br>
<br>T functionName(args) noexcept(noexcept(&lt;block of code&gt;))
<br>{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return &lt;block of cod=
e&gt;
<br>}
<br>
<br>Where the block of code is repeated. For example, in a commit I've just=
=20
<br>reviewed:
<br>
<br>template &lt;typename T, int Prealloc1, int Prealloc2&gt;
<br>bool operator&lt;(const QVarLengthArray&lt;T, Prealloc1&gt; &amp;lhs, c=
onst=20
<br>QVarLengthArray&lt;T, Prealloc2&gt; &amp;rhs)
<br>&nbsp; &nbsp; noexcept(noexcept(std::<wbr>lexicographical_compare(lhs.<=
wbr>begin(), lhs.end(),
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp;rhs.begin(), rhs.end())))
<br>{
<br>&nbsp; &nbsp; return std::lexicographical_compare(<wbr>lhs.begin(), lhs=
..end(),
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rhs.be=
gin(), rhs.end());
<br>}
<br>
<br>The first question that comes to mind is why we have to do that? If the=
=20
<br>compiler can tell that the block of code is noexcept and the function i=
s=20
<br>clearly inline, why do we need to add the noexcept declaration in the f=
irst=20
<br>place?
<br>
<br>A good reason for that is that you can't guarantee that the function wi=
ll=20
<br>always be inline. Binary compatibility aside, a new version of the code=
base=20
<br>could de-inline the code, so the declaration should still contain the=
=20
<br>necessary bits for noexcept.
<br>
<br>So I'd like to propose we add the ability to write "noexcept(auto)" in=
=20
<br>addition to "noexcept(true)' and "noexcept(false)" to indicate to the c=
ompiler=20
<br>that it should calculate whether the body of the inline function is noe=
xcept=20
<br>or not.
<br>
<br>More specifically, to [except.spec]/1, add:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;noexcept-<wbr>specifica=
tion:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;noexcept ( constant-expression )
<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;noexcept (auto)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;noexcept
<br>
<br>Then add a new paragraph after paragraph 1, before paragraph 2, explain=
ing=20
<br>that the "noexcept(auto)" specification may only appear in function def=
initions=20
<br>and what it is equivalent of.
<br>
<br>Does this seem reasonable?
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://www.google.=
com/url?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz\0751\46usg\75AFQjCNE=
swDUBNCNanbu7euhqLn_62FW8ag';return true;" onclick=3D"this.href=3D'http://w=
ww.google.com/url?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz\0751\46usg=
\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag';return true;">macieira.info</a> - th=
iago (AT) <a href=3D"http://kde.org" target=3D"_blank" rel=3D"nofollow" onm=
ousedown=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fkde.org=
\46sa\75D\46sntz\0751\46usg\75AFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA';return tr=
ue;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fkde=
..org\46sa\75D\46sntz\0751\46usg\75AFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA';retur=
n true;">kde.org</a>
<br>&nbsp; &nbsp;Software Architect - Intel Open Source Technology Center
<br>&nbsp; &nbsp; &nbsp; PGP/GPG: 0x6EF45358; fingerprint:
<br>&nbsp; &nbsp; &nbsp; E067 918B B660 DBD1 105C &nbsp;966C 33F5 F005 6EF4=
 5358
<br>
<br></blockquote></div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1467_13693775.1428175911784--
------=_Part_1466_1894749134.1428175911784--

.
