220 14496 <CADbh+eTq5TFWRdOz84YTc+Go03cOzr-05B4na=wwq2mkdXJVzQ@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Brent Friedman <fourthgeek@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Range-based if
Date: Wed, 12 Nov 2014 00:50:42 -0600
Lines: 145
Approved: news@gmane.org
Message-ID: <CADbh+eTq5TFWRdOz84YTc+Go03cOzr-05B4na=wwq2mkdXJVzQ@mail.gmail.com>
References: <CADbh+eQCaTPArs7YBUg9mYwrnJ2Gu3SRAfqUbPiLscpyxV8JqQ@mail.gmail.com>
	<m3tvcu$9ia$1@ger.gmane.org>
	<CADbh+eScmZMj4dcQv73re1dM0VNbw_PeHRc_FPWNONoKNKsiMg@mail.gmail.com>
	<1475323.QBNzPAHAPV@tjmaciei-mobl4>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a113d235c78d2a60507a3d057
X-Trace: ger.gmane.org 1415775050 26552 80.91.229.3 (12 Nov 2014 06:50:50 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 12 Nov 2014 06:50:50 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCHLPXGUXMJBBQUGRSRQKGQE5L5KIIY@isocpp.org Wed Nov 12 07:50:46 2014
Return-path: <std-proposals+bncBCHLPXGUXMJBBQUGRSRQKGQE5L5KIIY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f200.google.com ([209.85.216.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCHLPXGUXMJBBQUGRSRQKGQE5L5KIIY@isocpp.org>)
	id 1XoRlM-0002Jj-I6
	for gclcip-std-proposals@m.gmane.org; Wed, 12 Nov 2014 07:50:44 +0100
Original-Received: by mail-qc0-f200.google.com with SMTP id m20sf28076681qcx.11
        for <gclcip-std-proposals@m.gmane.org>; Tue, 11 Nov 2014 22:50:43 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=9sOzChItmAu91OShLgUvJpDRAzpMdBFCwi1g9ja5LLs=;
        b=Hk+AIi7OgDFo6xaQSFNbMiOkZ/+rUO3kbUFyq4uCwBGVXvKx6KcMN46z0SYyIgOFw2
         T0GUYdCDeRWunN3h3OxYpmVt9eF8wXPXaWnhzihu2PdjAmW/yUipvo4cIg+vEBEGSgWn
         nyXP+aTozbmDxgyZYMt/y924ByHrMQkwzqWQONnAwsfQujCdS/pyJ0ETMVTXOBqB0rkw
         M03uuOGl2HmpeV1bb1wXYGqBG12rVLWT77JIgDBjR5Va2ZAG7M4tEnO07vcH4rZy4+hM
         IHXY+jkXfGWH8iCqhpVFm4vLpEUkvOeagO0SEZ6EbFHB4Opzfi8yZrzmC0AXNP6fIAgY
         xeQw==
X-Gm-Message-State: ALoCoQlgXryNiEjku2luG1q/XZX6S1Aa0evNnGQy9X022rPEGAxOTUpreeGvdBsT2qIvfBavCaTr
X-Received: by 10.236.22.106 with SMTP id s70mr37694172yhs.7.1415775043682;
        Tue, 11 Nov 2014 22:50:43 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.79.66 with SMTP id h2ls1029156obx.5.gmail; Tue, 11 Nov
 2014 22:50:42 -0800 (PST)
X-Received: by 10.202.3.8 with SMTP id 8mr21073671oid.11.1415775042498;
        Tue, 11 Nov 2014 22:50:42 -0800 (PST)
Original-Received: from mail-ob0-x230.google.com (mail-ob0-x230.google.com. [2607:f8b0:4003:c01::230])
        by mx.google.com with ESMTPS id di4si25980376obb.57.2014.11.11.22.50.42
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Tue, 11 Nov 2014 22:50:42 -0800 (PST)
Received-SPF: pass (google.com: domain of fourthgeek@gmail.com designates 2607:f8b0:4003:c01::230 as permitted sender) client-ip=2607:f8b0:4003:c01::230;
Original-Received: by mail-ob0-f176.google.com with SMTP id va2so8551617obc.21
        for <std-proposals@isocpp.org>; Tue, 11 Nov 2014 22:50:42 -0800 (PST)
X-Received: by 10.202.88.138 with SMTP id m132mr823669oib.62.1415775042194;
 Tue, 11 Nov 2014 22:50:42 -0800 (PST)
Original-Received: by 10.202.232.77 with HTTP; Tue, 11 Nov 2014 22:50:42 -0800 (PST)
In-Reply-To: <1475323.QBNzPAHAPV@tjmaciei-mobl4>
X-Original-Sender: fourthgeek@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of fourthgeek@gmail.com designates 2607:f8b0:4003:c01::230 as
 permitted sender) smtp.mail=fourthgeek@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=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:14496
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14496>

--001a113d235c78d2a60507a3d057
Content-Type: text/plain; charset=UTF-8

> I must be missing something: what wasn't reachable?

When you break on the first iteration, the code that advances the iterator
can never be executed. We see this both for 'normal' for loops and for
range-for loops.

It might be easy to say that this is something that vendors should fix, but
I think that the warning is good and valuable as it is. By turning on this
warning we've found a few places where the premature loop exit was actually
unintentional. This is why I think a different control structure might be a
better solution. It can make intent clearer to man and machine.

On Tue, Nov 11, 2014 at 10:13 PM, Thiago Macieira <thiago@macieira.org>
wrote:

> On Tuesday 11 November 2014 20:39:32 Brent Friedman wrote:
> > Anecdotally, in our codebase of a million or so LOC, this pattern of
> using
> > a looping structure to get the first element in a range constituted about
> > 70% of our unreachable code instances.
>
> I must be missing something: what wasn't reachable?
>
> All three non-comment lines in your example would be executed for a
> non-empty
> range:
>
> for (auto& Item : range)
> {
>     DoSomething(Item);
>     break;
> }
>
> --
> 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/.
>

-- 

--- 
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/.

--001a113d235c78d2a60507a3d057
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">&gt;=C2=A0<span style=3D"font-family:arial,sans-serif;font=
-size:13px">I must be missing something: what wasn&#39;t reachable?</span><=
div><span style=3D"font-family:arial,sans-serif;font-size:13px"><br></span>=
</div><div><font face=3D"arial, sans-serif">When you break on the first ite=
ration, the code that advances the iterator can never be executed. We see t=
his both for &#39;normal&#39; for loops and for range-for loops.</font></di=
v><div><font face=3D"arial, sans-serif"><br></font></div><div><font face=3D=
"arial, sans-serif">It might be easy to say that this is something that ven=
dors should fix, but I think that the warning is good and valuable as it is=
.. By turning on this warning we&#39;ve found a few places where the prematu=
re loop exit was actually unintentional. This is why I think a different co=
ntrol structure might be a better solution. It can make intent clearer to m=
an and machine.</font></div></div><div class=3D"gmail_extra"><br><div class=
=3D"gmail_quote">On Tue, Nov 11, 2014 at 10:13 PM, Thiago Macieira <span di=
r=3D"ltr">&lt;<a href=3D"mailto:thiago@macieira.org" target=3D"_blank">thia=
go@macieira.org</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><sp=
an class=3D"">On Tuesday 11 November 2014 20:39:32 Brent Friedman wrote:<br=
>
&gt; Anecdotally, in our codebase of a million or so LOC, this pattern of u=
sing<br>
&gt; a looping structure to get the first element in a range constituted ab=
out<br>
&gt; 70% of our unreachable code instances.<br>
<br>
</span>I must be missing something: what wasn&#39;t reachable?<br>
<br>
All three non-comment lines in your example would be executed for a non-emp=
ty<br>
range:<br>
<span class=3D"im HOEnZb"><br>
for (auto&amp; Item : range)<br>
{<br>
=C2=A0 =C2=A0 DoSomething(Item);<br>
=C2=A0 =C2=A0 break;<br>
}<br>
<br>
</span><span class=3D"HOEnZb"><font color=3D"#888888">--<br>
Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=3D"_b=
lank">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank">kde.org</a><br>
=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center<br>
=C2=A0 =C2=A0 =C2=A0 PGP/GPG: 0x6EF45358; fingerprint:<br>
=C2=A0 =C2=A0 =C2=A0 E067 918B B660 DBD1 105C=C2=A0 966C 33F5 F005 6EF4 535=
8<br>
</font></span><div class=3D"HOEnZb"><div class=3D"h5"><br>
--<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%2Bunsubscribe@isocpp.org">std-propo=
sals+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/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></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 />

--001a113d235c78d2a60507a3d057--

.
