220 24186 <ec9e6080-1bed-4d84-a9a2-e7d56d784377@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Edward Catmur <ed@catmur.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal: Change the specified behavior when
 control flow reaches the end of non-void functions
Date: Thu, 4 Feb 2016 02:57:30 -0800 (PST)
Lines: 152
Approved: news@gmane.org
Message-ID: <ec9e6080-1bed-4d84-a9a2-e7d56d784377@isocpp.org>
References: <5115b78c-8fb4-4c72-a278-f74c636f5217@isocpp.org>
 <CAEhD+6CnZh=pHETBZ39WaaLGVovRV0CfsSJ8-qeoq1PSHz=LKw@mail.gmail.com>
 <d1c407b1-6b45-4042-8425-cdd48d53adbf@isocpp.org>
 <CAEhD+6Dwi4Mb3M-NZPqRSD+ayO8XtVYYpjGZ3HKfF4r-xL5PZg@mail.gmail.com>
 <CAEhD+6B262A5dUuUOnKO7z_EnQki62OgHw0v3p_OahonSvZTwA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1253_803925918.1454583450835"
X-Trace: ger.gmane.org 1454583464 6618 80.91.229.3 (4 Feb 2016 10:57:44 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 4 Feb 2016 10:57:44 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDZLZTXF7UJBBG65ZS2QKGQE4EFIAPA@isocpp.org Thu Feb 04 11:57:44 2016
Return-path: <std-proposals+bncBDZLZTXF7UJBBG65ZS2QKGQE4EFIAPA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f198.google.com ([209.85.220.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDZLZTXF7UJBBG65ZS2QKGQE4EFIAPA@isocpp.org>)
	id 1aRHbW-0002l4-HO
	for gclcip-std-proposals@m.gmane.org; Thu, 04 Feb 2016 11:57:38 +0100
Original-Received: by mail-qk0-f198.google.com with SMTP id e124sf76207057qkc.3
        for <gclcip-std-proposals@m.gmane.org>; Thu, 04 Feb 2016 02:57:38 -0800 (PST)
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
         :content-type: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=4EfIbirp/JQ2AoOL6/gltH5W6drBaLY4Cu7EclnSvoM=;
        b=ZpihU5pTp6TU4cR9ilz9KLb+jLGjC4w8IhxGrTP8tZjrSYwi2H1/4K3Rrw5D1or6nB
         Ks478AlrGkW28SgM1IyY4PPCxOM6Q5IoPeLFatFA/arREHllX1AWxbIKcjosA0CeRF50
         DMLOJddwOqY1lQeBqd/36y8tb9u4wT2BTRJWK/N1/csqq3bJCcNfZa1aTklwbUW4cfZi
         vXOboF7nX4pMmxEkTsx/oxw+uvy4Beb2MPutBQ5Dp8O9KRKB7zcCdFad7NNfPhaWaS01
         8muap3l9MUviDFyMKjUyS57i/5YKW/jFJqbKb984nXGaZAO40NXj2QMRM7m08ibTKEZ8
         Wf2A==
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:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=4EfIbirp/JQ2AoOL6/gltH5W6drBaLY4Cu7EclnSvoM=;
        b=cfM+3M2zm8AL4nus8OoANijnWjdMQal/6t/tUxOfmsZ2PFY9Q1ndC1+PJOcUMBjP9c
         G3TbLjsrZ/6FbVHKlwFyxIrxRQHl7B9pM1WFT1UU0vv3XYb2z2rp0WM4YNqAu1/XJSB5
         MWJsaPKALRSWRxdVp8O2c+mqA0KHcFtZAtiXj1JsbsWtjyP2A3W2p2E2zZYvNwcJ2dAH
         fT4dNAuls/1hYi/EyVAMXjaHwLUZDMhxGJJsvRBRL6usrslHbMx0GJPmrTNAUSQFZzu1
         CeNeHHCaypWwHEE2/5nYnQKGXmvJLR+ElET5X3Q7igSUIMyeqIp5420EqnoFviYLYT9o
         A/Bg==
X-Gm-Message-State: AG10YOR1vHjt0SNXkZZgMQ0hDO0EcqacT0dIp7Re4lrL1c0u3IeyS4wYI0wnkDW7FN561w==
X-Received: by 10.13.202.7 with SMTP id m7mr6117906ywd.54.1454583452775;
        Thu, 04 Feb 2016 02:57:32 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.67.46 with SMTP id k14ls2268591igt.44.canary; Thu, 04 Feb
 2016 02:57:31 -0800 (PST)
X-Received: by 10.50.136.193 with SMTP id qc1mr108946igb.6.1454583451719;
        Thu, 04 Feb 2016 02:57:31 -0800 (PST)
In-Reply-To: <CAEhD+6B262A5dUuUOnKO7z_EnQki62OgHw0v3p_OahonSvZTwA@mail.gmail.com>
X-Original-Sender: ed@catmur.co.uk
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:24186
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/24186>

------=_Part_1253_803925918.1454583450835
Content-Type: multipart/alternative; 
	boundary="----=_Part_1254_936790487.1454583450835"

------=_Part_1254_936790487.1454583450835
Content-Type: text/plain; charset=UTF-8

On Wednesday, 3 February 2016 12:02:55 UTC, Tony V E wrote:
>
> Since it is currently undefined behaviour, you could ask your compiler 
> vendor to offer it as a compiler option, and then we could get some 
> experience as to how valuable it is.
>

Both clang and gcc have this in ubsan (-fsanitize=undefined), specifically 
as -fsanitize=return (clang's implementation seems better than gcc's).

They don't turn it on by default as it pessimizes valid code. Thiago has 
already given examples; here's another that comes up fairly often:

enum e { a, b, c };
enum E { A, B, C };
E f(e v) {
  switch (v) {
    case a: return A;
    case b: return B;
    case c: return C;
  }
}

Currently clang compiles this to mov edi, eax; ret. 
With -fsanitize=return the instruction count quadruples, including a branch.

The proposal would be worse than the current ubsan offering, not just in 
making it compulsory but also because calling std::terminate discards 
information on the nature and location of the error; ubsan outputs the 
source location and describes the error: "main.c:3:3: missing return 
statement", or some such.

-- 

--- 
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1254_936790487.1454583450835
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>On Wednesday, 3 February 2016 12:02:55 UTC, Tony V E =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex;=
 border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left=
-style: solid; padding-left: 1ex;"><div lang=3D"en-US" style=3D"line-height=
: initial;"><div style=3D"width: 812.40625px; font-size: initial; font-fami=
ly: Calibri, &#39;Slate Pro&#39;, sans-serif, sans-serif; color: rgb(31, 73=
, 125); text-align: initial;">Since it is currently undefined behaviour, yo=
u could ask your compiler vendor to offer it as a compiler option, and then=
 we could get some experience as to how valuable it is.</div></div></blockq=
uote><div><br></div><div>Both clang and gcc have this in ubsan (-fsanitize=
=3Dundefined), specifically as -fsanitize=3Dreturn (clang&#39;s implementat=
ion seems better than gcc&#39;s).</div><div><br></div><div>They don&#39;t t=
urn it on by default as it pessimizes valid code. Thiago has already given =
examples; here&#39;s another that comes up fairly often:</div></div><div><b=
r></div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187,=
 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code =
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #=
008;" class=3D"styled-by-prettify">enum</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> e </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> c </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">enum</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> E </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> A</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> B=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> C </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>E f</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">e v</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">sw=
itch</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">v</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">case</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> A</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">case</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> b</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> B</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">case</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> c</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> C</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span></div></code></div><div><br>Currently clang compiles t=
his to mov edi, eax; ret. With=C2=A0-fsanitize=3Dreturn=C2=A0the instructio=
n count quadruples, including a branch.</div><div><br></div><div>The propos=
al would be worse than the current ubsan offering, not just in making it co=
mpulsory but also because calling std::terminate discards information on th=
e nature and location of the error; ubsan outputs the source location and d=
escribes the error: &quot;main.c:3:3: missing return statement&quot;, or so=
me such.</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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_1254_936790487.1454583450835--
------=_Part_1253_803925918.1454583450835--

.
