<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Mar 10, 2014, at 7:49 , Tom Honermann <<a href="mailto:thonermann@coverity.com">thonermann@coverity.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On 03/10/2014 10:23 AM, Per Viberg wrote:<br><blockquote type="cite"><br>Hi all,<br><br>I was inspecting the AST dump of this switch:<br><br>void test_switch(int t) {<br>   switch(t)<br>   {<br>   case 1:<br>     y = 11;<br>   case 2:<br>     y = 9;<br>     x = 12;<br>     break;<br>   default:<br>     break;<br>   }<br>}<br><br>and I got something I didn't expect. The second CaseStmt does only<br>contain the first statement that is under it's label. The "x=12;" gets<br>its own Stmt outside the CaseStmt but inside the CompoundStmt inside the<br>SwitchStmt. I would anticipate that all statements under a label either<br>are: inside the CaseStmt or: outside but inside the CompoundStmt. Any<br>reason for this?.<br></blockquote><br>This is expected.  Case statements have just one sub statement.<br></blockquote></div><br><div>More generally, case statements are just labels, and have the same basic rules as regular old goto labels. Having case statements "just" be labels is what allows things like <a href="http://en.wikipedia.org/wiki/Duff's_device">Duff's Device</a> in C:</div><div><br></div><div>switch(count % 8) {<span class="Apple-tab-span" style="white-space: pre;">      </span><br>case 0:<span class="Apple-tab-span" style="white-space:pre">      </span>do {<span class="Apple-tab-span" style="white-space:pre">   </span>*to = *from++;<br>case 7:<span class="Apple-tab-span" style="white-space:pre">              </span>*to = *from++;<br>case 6:<span class="Apple-tab-span" style="white-space:pre">              </span>*to = *from++;<br>case 5:<span class="Apple-tab-span" style="white-space:pre">              </span>*to = *from++;<br>case 4:<span class="Apple-tab-span" style="white-space:pre">              </span>*to = *from++;<br>case 3:<span class="Apple-tab-span" style="white-space:pre">              </span>*to = *from++;<br>case 2:<span class="Apple-tab-span" style="white-space:pre">              </span>*to = *from++;<br>case 1:<span class="Apple-tab-span" style="white-space:pre">              </span>*to = *from++;<br><span class="Apple-tab-span" style="white-space:pre">  </span>} while(--n > 0);<br>}</div><div><br></div><div>This is the opposite situation, really, because here we need cases <i>inside</i> the loop that's inside the switch. But once you're supporting this, the representation as a simple label is just easier to work with.</div><div><br></div><div>Jordan<br><br></div></body></html>