Topic: Why is it not possible to communicate intent in a


Author: alexvanderwalathome@gmail.com
Date: Tue, 10 Oct 2017 05:33:21 -0700 (PDT)
Raw View
------=_Part_7524_1905349239.1507638801359
Content-Type: multipart/alternative;
 boundary="----=_Part_7525_1017925529.1507638801360"

------=_Part_7525_1017925529.1507638801360
Content-Type: text/plain; charset="UTF-8"

I cannot imagine that this subject has not already been debated to death.
My apologies about any ignorance on my part.
I am curious as to why this issue has never been resolved in the language
itself.
My question here is whether the community thinks this is worth addressing,
and if it is whether it is worth solving in the core language.

Short version for a potential solution:

Abstract: Extend the core language to communicate intent about switch case
statements that have 'fallthrough' behavior.
Rationale: Compile-time fault detection.
Proposal: In order to communicate the intent that a switch case does not
end with a break; statement on purpose, use 'case continue;'.
Benefits: It allows the compiler to issue a warning if case statements have
no break; or case continue; statement.

Long version:

The venerable switch statement has an issue where if a switch case does not
end with a break; statement, it is not certain whether that is intentional
or a fault (well, to the compiler at least).
IDEs (such as Eclipse) assist by marking this as a potential fault and
allow you to show intent it by supplying a specific comment line. Needless
to say, expressing intent via comments is not great.

If there is an alternative to the break; statement inside a switch then
that directly communicates intent and allows the compiler to perform the
same checks as IDEs.

Candidates:
continue; Does not work since it would change behavior for existing code
where a switch is enclosed in a for loop.
fallthrough; This is a new keyword and if there is an alternative then that
should be explored first.
case continue; So not a label, but a combined statement of case and
continue. This is a new language feature. It is easily distinguishable from
other case statements since 'continue' is never an integral constant.

case continue; is equivalent to a goto statement for a label that is placed
in front of the first line of code of the next case statement within the
same switch block. If there is none, it behaves like break;

Example code (horrible as is tradition for these things):

for (;;) {
switch (i) {
case 42:
if (douglasAdams())
continue; // Existing behavior.
break;
case 46:
if (valentinoRossi())
break;  // Existing behavior.
case continue; // Fallthrough intended.
// Any code placed here triggers a compiler warning about the fact that it
is unreachable.
case 47:
f(i);
// No break; or case continue; so a compiler warning is desired.
default:
// Other code.
break;
    }
}

It should also be possible to use case continue; in other places within a
switch case:

case 3:
  if (f(i)) {
    case continue; // Effectively a goto case 4:
  }
  g(i);
  break;
case 4:

Thoughts?

--
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/a463917a-eb66-4a0d-bb22-92177dac1549%40isocpp.org.

------=_Part_7525_1017925529.1507638801360
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I cannot imagine that this subject has not already be=
en debated to death. My apologies about any ignorance on my part.=C2=A0</di=
v><div>I am curious as to why this issue has never been resolved in the lan=
guage itself.</div><div>My question here is whether the community thinks th=
is is worth addressing, and if it is whether it is worth solving in the cor=
e language.</div><div><br></div>Short version for a potential solution:<div=
><br></div><div>Abstract: Extend the core language to communicate intent ab=
out switch case statements that have &#39;fallthrough&#39; behavior.</div><=
div>Rationale: Compile-time fault detection.<br><div>Proposal: In order to =
communicate the intent that a switch case does not end with a break; statem=
ent on purpose, use &#39;case continue;&#39;.</div></div><div>Benefits: It =
allows the compiler to issue a warning if case statements have no break; or=
 case continue; statement.</div><div><br></div><div>Long version:</div><div=
><br></div><div>The venerable switch statement has an issue where if a swit=
ch case does not end with a break; statement, it is not certain whether tha=
t is intentional or a fault (well, to the compiler at least).</div><div>IDE=
s (such as Eclipse) assist by marking this as a potential fault and allow y=
ou to show intent it by supplying a specific comment line. Needless to say,=
 expressing intent via comments is not great.</div><div><br></div><div>If t=
here is an alternative to the break; statement inside a switch then that di=
rectly communicates intent and allows the compiler to perform the same chec=
ks as IDEs.</div><div><br></div><div>Candidates:</div><div>continue; Does n=
ot work since it would change behavior for existing code where a switch is =
enclosed in a for loop.</div><div>fallthrough; This is a new keyword and if=
 there is an alternative then that should be explored first.</div><div>case=
 continue; So not a label, but a combined statement of case and continue. T=
his is a new language feature. It is easily distinguishable from other case=
 statements since &#39;continue&#39; is never an integral constant.</div><d=
iv><br></div><div>case continue; is equivalent to a goto statement for a la=
bel that is placed in front of the first line of code of the next case stat=
ement within the same switch block. If there is none, it behaves like break=
;</div><div><br></div><div>Example code (horrible as is tradition for these=
 things):</div><div><br></div><div><div>for (;;) {</div><div><span style=3D=
"white-space:pre"> </span>switch (i) {</div><div><span style=3D"white-space=
:pre"> </span>case 42:</div><div><span style=3D"white-space:pre">  </span>i=
f (douglasAdams())</div><div><span style=3D"white-space:pre">   </span>cont=
inue; // Existing behavior.</div><div><span style=3D"white-space: pre;">  <=
/span>break;<br></div><div><span style=3D"white-space:pre"> </span>case 46:=
</div><div><span style=3D"white-space: pre;"> </span><span style=3D"white-s=
pace: pre;"> </span>if (valentinoRossi())</div><div><span style=3D"white-sp=
ace:pre">   </span>break;=C2=A0 // Existing behavior.</div><div><span style=
=3D"white-space: pre;"> </span><span style=3D"white-space: pre;"> </span>ca=
se continue; // Fallthrough intended.</div><div><span style=3D"white-space:=
 pre;"> </span><span style=3D"white-space: pre;"> </span>// Any code placed=
 here triggers a compiler warning about the fact that it is unreachable.</d=
iv><div><span style=3D"white-space:pre"> </span>case 47:</div><div><span st=
yle=3D"white-space:pre">  </span>f(i);</div><div><span style=3D"white-space=
:pre">  </span>// No break; or case continue; so a compiler warning is desi=
red.</div><div><span style=3D"white-space:pre"> </span>default:</div><div><=
span style=3D"white-space:pre">  </span>// Other code.</div><div><span styl=
e=3D"white-space:pre">  </span>break;</div><div>=C2=A0 =C2=A0 }</div><div>}=
</div></div><div><br></div><div>It should also be possible to use case cont=
inue; in other places within a switch case:</div><div><br></div><div>case 3=
:</div><div>=C2=A0 if (f(i)) {</div><div>=C2=A0 =C2=A0 case continue; // Ef=
fectively a goto case 4:</div><div>=C2=A0 }</div><div>=C2=A0 g(i);</div><di=
v>=C2=A0 break;</div><div>case 4:</div><div><br></div><div>Thoughts?<br></d=
iv></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a463917a-eb66-4a0d-bb22-92177dac1549%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a463917a-eb66-4a0d-bb22-92177dac1549=
%40isocpp.org</a>.<br />

------=_Part_7525_1017925529.1507638801360--

------=_Part_7524_1905349239.1507638801359--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 10 Oct 2017 15:39:27 +0300
Raw View
On 10 October 2017 at 15:33,  <alexvanderwalathome@gmail.com> wrote:
> I cannot imagine that this subject has not already been debated to death. My
> apologies about any ignorance on my part.


Here's a nickel, go buy a new standard for you:
http://eel.is/c++draft/dcl.attr.fallthrough

--
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/CAFk2RUbCX%3DUsvSYO-Q8XK7M7MBTqkAGEheuR7Y1GVigfmMT9xw%40mail.gmail.com.

.


Author: Alex van der Wal <alexvanderwalathome@gmail.com>
Date: Tue, 10 Oct 2017 14:45:28 +0200
Raw View
--001a114db37c95bee7055b30aef4
Content-Type: text/plain; charset="UTF-8"

I stand corrected and on the shoulder of giants.
Thank you. Case closed (pun intended).

On Tue, Oct 10, 2017 at 2:39 PM, Ville Voutilainen <
ville.voutilainen@gmail.com> wrote:

> On 10 October 2017 at 15:33,  <alexvanderwalathome@gmail.com> wrote:
> > I cannot imagine that this subject has not already been debated to
> death. My
> > apologies about any ignorance on my part.
>
>
> Here's a nickel, go buy a new standard for you:
> http://eel.is/c++draft/dcl.attr.fallthrough
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this topic, visit https://groups.google.com/a/
> isocpp.org/d/topic/std-proposals/MoXC9p57ero/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAFk2RUbCX%3DUsvSYO-
> Q8XK7M7MBTqkAGEheuR7Y1GVigfmMT9xw%40mail.gmail.com.
>

--
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/CAAJhKzf5EbPGOSjBTzSfiGoYMvJUNvpeLsbLWaQgwOnW7P4sBQ%40mail.gmail.com.

--001a114db37c95bee7055b30aef4
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I stand corrected and on the shoulder of giants.<div>Thank=
 you. Case closed (pun intended).</div></div><div class=3D"gmail_extra"><br=
><div class=3D"gmail_quote">On Tue, Oct 10, 2017 at 2:39 PM, Ville Voutilai=
nen <span dir=3D"ltr">&lt;<a href=3D"mailto:ville.voutilainen@gmail.com" ta=
rget=3D"_blank">ville.voutilainen@gmail.com</a>&gt;</span> wrote:<br><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
 solid;padding-left:1ex"><span class=3D"">On 10 October 2017 at 15:33,=C2=
=A0 &lt;<a href=3D"mailto:alexvanderwalathome@gmail.com">alexvanderwalathom=
e@gmail.com</a><wbr>&gt; wrote:<br>
&gt; I cannot imagine that this subject has not already been debated to dea=
th. My<br>
&gt; apologies about any ignorance on my part.<br>
<br>
<br>
</span>Here&#39;s a nickel, go buy a new standard for you:<br>
<a href=3D"http://eel.is/c++draft/dcl.attr.fallthrough" rel=3D"noreferrer" =
target=3D"_blank">http://eel.is/c++draft/dcl.<wbr>attr.fallthrough</a><br>
<span class=3D""><br>
--<br>
You received this message because you are subscribed to a topic in the Goog=
le Groups &quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
a/isocpp.org/d/topic/std-proposals/MoXC9p57ero/unsubscribe" rel=3D"noreferr=
er" target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/d/topic/s=
td-<wbr>proposals/MoXC9p57ero/<wbr>unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-proposals+unsubscrib=
e@<wbr>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>
</span>To view this discussion on the web visit <a href=3D"https://groups.g=
oogle.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUbCX%3DUsvSYO-Q8XK7M7MBT=
qkAGEheuR7Y1GVigfmMT9xw%40mail.gmail.com" rel=3D"noreferrer" target=3D"_bla=
nk">https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/=
CAFk2RUbCX%3DUsvSYO-<wbr>Q8XK7M7MBTqkAGEheuR7Y1GVigfmMT<wbr>9xw%40mail.gmai=
l.com</a>.<br>
</blockquote></div><br></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAAJhKzf5EbPGOSjBTzSfiGoYMvJUNvpeLsbL=
WaQgwOnW7P4sBQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAAJhKzf5EbPGOSjB=
TzSfiGoYMvJUNvpeLsbLWaQgwOnW7P4sBQ%40mail.gmail.com</a>.<br />

--001a114db37c95bee7055b30aef4--

.


Author: =?UTF-8?Q?=27Thomas_K=C3=B6ppe=27_via_ISO_C=2B=2B_Standard_=2D_Future_Proposals?= <std-proposals@isocpp.org>
Date: Tue, 10 Oct 2017 16:59:38 -0700 (PDT)
Raw View
------=_Part_8635_1919563781.1507679978850
Content-Type: multipart/alternative;
 boundary="----=_Part_8636_1053576685.1507679978851"

------=_Part_8636_1053576685.1507679978851
Content-Type: text/plain; charset="UTF-8"

On Tuesday, 10 October 2017 13:39:30 UTC+1, Ville Voutilainen wrote:
>
> On 10 October 2017 at 15:33,  <alexvande...@gmail.com <javascript:>>
> wrote:
> > I cannot imagine that this subject has not already been debated to
> death. My
> > apologies about any ignorance on my part.
>
> Here's a nickel, go buy a new standard for you:
> http://eel.is/c++draft/dcl.attr.fallthrough
>

However, note that the ISO pricing policies make sure that no amount of
nickels will buy you *any* actual Standard :-(

--
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/86717e45-b90d-49cd-a14d-2fa1e8fc83c9%40isocpp.org.

------=_Part_8636_1053576685.1507679978851
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, 10 October 2017 13:39:30 UTC+1, Ville Voutilai=
nen  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 10 October 2017 =
at 15:33, =C2=A0&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscate=
d-mailto=3D"mbqXxImtAQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;=
javascript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;=
;return true;">alexvande...@gmail.<wbr>com</a>&gt; wrote:
<br>&gt; I cannot imagine that this subject has not already been debated to=
 death. My
<br>&gt; apologies about any ignorance on my part.
<br><br>Here&#39;s a nickel, go buy a new standard for you:
<br><a href=3D"http://eel.is/c++draft/dcl.attr.fallthrough" target=3D"_blan=
k" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.com/u=
rl?q\x3dhttp%3A%2F%2Feel.is%2Fc%2B%2Bdraft%2Fdcl.attr.fallthrough\x26sa\x3d=
D\x26sntz\x3d1\x26usg\x3dAFQjCNGOlsEFsAvjwHxFkqTp0G-W7gSTgw&#39;;return tru=
e;" onclick=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2=
Feel.is%2Fc%2B%2Bdraft%2Fdcl.attr.fallthrough\x26sa\x3dD\x26sntz\x3d1\x26us=
g\x3dAFQjCNGOlsEFsAvjwHxFkqTp0G-W7gSTgw&#39;;return true;">http://eel.is/c+=
+draft/dcl.<wbr>attr.fallthrough</a>
<br></blockquote><div><br></div><div>However, note that the ISO pricing pol=
icies make sure that no amount of nickels will buy you <i>any</i> actual St=
andard :-(</div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/86717e45-b90d-49cd-a14d-2fa1e8fc83c9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/86717e45-b90d-49cd-a14d-2fa1e8fc83c9=
%40isocpp.org</a>.<br />

------=_Part_8636_1053576685.1507679978851--

------=_Part_8635_1919563781.1507679978850--

.


Author: Aaron McDaid <aaronmcdaid@gmail.com>
Date: Fri, 13 Oct 2017 14:46:22 -0700 (PDT)
Raw View
------=_Part_13589_1345353100.1507931183011
Content-Type: multipart/alternative;
 boundary="----=_Part_13590_230554740.1507931183012"

------=_Part_13590_230554740.1507931183012
Content-Type: text/plain; charset="UTF-8"

for (;;) {
switch (i) {
break; case 42:
                       fortytwo();
      break; case 46:
                       fortysix();
            break; default:
                       Default();
    }
}

This is the correct way to format 'switch' statements. If a 'break' is
missing, it's very obvious to the reader that it is missing. Any 'case' or
'default' not immediately *preceded* by a 'break' is suspicious.

Aaron

On Tuesday, 10 October 2017 13:33:21 UTC+1, alexvande...@gmail.com wrote:
>
> I cannot imagine that this subject has not already been debated to death.
> My apologies about any ignorance on my part.
> I am curious as to why this issue has never been resolved in the language
> itself.
> My question here is whether the community thinks this is worth addressing,
> and if it is whether it is worth solving in the core language.
>
> Short version for a potential solution:
>
> Abstract: Extend the core language to communicate intent about switch case
> statements that have 'fallthrough' behavior.
> Rationale: Compile-time fault detection.
> Proposal: In order to communicate the intent that a switch case does not
> end with a break; statement on purpose, use 'case continue;'.
> Benefits: It allows the compiler to issue a warning if case statements
> have no break; or case continue; statement.
>
> Long version:
>
> The venerable switch statement has an issue where if a switch case does
> not end with a break; statement, it is not certain whether that is
> intentional or a fault (well, to the compiler at least).
> IDEs (such as Eclipse) assist by marking this as a potential fault and
> allow you to show intent it by supplying a specific comment line. Needless
> to say, expressing intent via comments is not great.
>
> If there is an alternative to the break; statement inside a switch then
> that directly communicates intent and allows the compiler to perform the
> same checks as IDEs.
>
> Candidates:
> continue; Does not work since it would change behavior for existing code
> where a switch is enclosed in a for loop.
> fallthrough; This is a new keyword and if there is an alternative then
> that should be explored first.
> case continue; So not a label, but a combined statement of case and
> continue. This is a new language feature. It is easily distinguishable from
> other case statements since 'continue' is never an integral constant.
>
> case continue; is equivalent to a goto statement for a label that is
> placed in front of the first line of code of the next case statement within
> the same switch block. If there is none, it behaves like break;
>
> Example code (horrible as is tradition for these things):
>
> for (;;) {
> switch (i) {
> case 42:
> if (douglasAdams())
> continue; // Existing behavior.
> break;
> case 46:
> if (valentinoRossi())
> break;  // Existing behavior.
> case continue; // Fallthrough intended.
> // Any code placed here triggers a compiler warning about the fact that it
> is unreachable.
> case 47:
> f(i);
> // No break; or case continue; so a compiler warning is desired.
> default:
> // Other code.
> break;
>     }
> }
>
> It should also be possible to use case continue; in other places within a
> switch case:
>
> case 3:
>   if (f(i)) {
>     case continue; // Effectively a goto case 4:
>   }
>   g(i);
>   break;
> case 4:
>
> Thoughts?
>

--
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/137ae3ac-1d54-4595-a7a2-2725395f7510%40isocpp.org.

------=_Part_13590_230554740.1507931183012
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div>for (;;) {</div><div><span style=3D"white-space:=
pre"> </span>switch (i) {</div><div><span style=3D"white-space:pre">     </=
span>break; case 42:<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 fortytwo();<br></div><div><span style=3D"white-space:pre">=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0       </span>break; case 46:<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fortysix();<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; default:<br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Default();<br></div><div>=
=C2=A0 =C2=A0 }</div><div>}</div></div><br>This is the correct way to forma=
t &#39;switch&#39; statements. If a &#39;break&#39; is missing, it&#39;s ve=
ry obvious to the reader that it is missing. Any &#39;case&#39; or &#39;def=
ault&#39; not immediately *preceded* by a &#39;break&#39; is suspicious.<br=
><br>Aaron<br><br>On Tuesday, 10 October 2017 13:33:21 UTC+1, alexvande...@=
gmail.com  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr"><div>I cannot imagine that this subject has not already been debated to=
 death. My apologies about any ignorance on my part.=C2=A0</div><div>I am c=
urious as to why this issue has never been resolved in the language itself.=
</div><div>My question here is whether the community thinks this is worth a=
ddressing, and if it is whether it is worth solving in the core language.</=
div><div><br></div>Short version for a potential solution:<div><br></div><d=
iv>Abstract: Extend the core language to communicate intent about switch ca=
se statements that have &#39;fallthrough&#39; behavior.</div><div>Rationale=
: Compile-time fault detection.<br><div>Proposal: In order to communicate t=
he intent that a switch case does not end with a break; statement on purpos=
e, use &#39;case continue;&#39;.</div></div><div>Benefits: It allows the co=
mpiler to issue a warning if case statements have no break; or case continu=
e; statement.</div><div><br></div><div>Long version:</div><div><br></div><d=
iv>The venerable switch statement has an issue where if a switch case does =
not end with a break; statement, it is not certain whether that is intentio=
nal or a fault (well, to the compiler at least).</div><div>IDEs (such as Ec=
lipse) assist by marking this as a potential fault and allow you to show in=
tent it by supplying a specific comment line. Needless to say, expressing i=
ntent via comments is not great.</div><div><br></div><div>If there is an al=
ternative to the break; statement inside a switch then that directly commun=
icates intent and allows the compiler to perform the same checks as IDEs.</=
div><div><br></div><div>Candidates:</div><div>continue; Does not work since=
 it would change behavior for existing code where a switch is enclosed in a=
 for loop.</div><div>fallthrough; This is a new keyword and if there is an =
alternative then that should be explored first.</div><div>case continue; So=
 not a label, but a combined statement of case and continue. This is a new =
language feature. It is easily distinguishable from other case statements s=
ince &#39;continue&#39; is never an integral constant.</div><div><br></div>=
<div>case continue; is equivalent to a goto statement for a label that is p=
laced in front of the first line of code of the next case statement within =
the same switch block. If there is none, it behaves like break;</div><div><=
br></div><div>Example code (horrible as is tradition for these things):</di=
v><div><br></div><div><div>for (;;) {</div><div><span style=3D"white-space:=
pre"> </span>switch (i) {</div><div><span style=3D"white-space:pre"> </span=
>case 42:</div><div><span style=3D"white-space:pre">  </span>if (douglasAda=
ms())</div><div><span style=3D"white-space:pre">   </span>continue; // Exis=
ting behavior.</div><div><span style=3D"white-space:pre">  </span>break;<br=
></div><div><span style=3D"white-space:pre"> </span>case 46:</div><div><spa=
n style=3D"white-space:pre"> </span><span style=3D"white-space:pre"> </span=
>if (valentinoRossi())</div><div><span style=3D"white-space:pre">   </span>=
break;=C2=A0 // Existing behavior.</div><div><span style=3D"white-space:pre=
"> </span><span style=3D"white-space:pre"> </span>case continue; // Fallthr=
ough intended.</div><div><span style=3D"white-space:pre"> </span><span styl=
e=3D"white-space:pre"> </span>// Any code placed here triggers a compiler w=
arning about the fact that it is unreachable.</div><div><span style=3D"whit=
e-space:pre"> </span>case 47:</div><div><span style=3D"white-space:pre">  <=
/span>f(i);</div><div><span style=3D"white-space:pre">  </span>// No break;=
 or case continue; so a compiler warning is desired.</div><div><span style=
=3D"white-space:pre"> </span>default:</div><div><span style=3D"white-space:=
pre">  </span>// Other code.</div><div><span style=3D"white-space:pre">  </=
span>break;</div><div>=C2=A0 =C2=A0 }</div><div>}</div></div><div><br></div=
><div>It should also be possible to use case continue; in other places with=
in a switch case:</div><div><br></div><div>case 3:</div><div>=C2=A0 if (f(i=
)) {</div><div>=C2=A0 =C2=A0 case continue; // Effectively a goto case 4:</=
div><div>=C2=A0 }</div><div>=C2=A0 g(i);</div><div>=C2=A0 break;</div><div>=
case 4:</div><div><br></div><div>Thoughts?<br></div></div></blockquote></di=
v>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/137ae3ac-1d54-4595-a7a2-2725395f7510%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/137ae3ac-1d54-4595-a7a2-2725395f7510=
%40isocpp.org</a>.<br />

------=_Part_13590_230554740.1507931183012--

------=_Part_13589_1345353100.1507931183011--

.