<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello Jacob,<div class=""><br class=""></div><div class="">This is an excellent question.</div><div class=""><br class=""></div><div class="">This falls out of the grammar of a labeled statement: <a href="https://cigix.me/c17#6.8.1" class="">https://cigix.me/c17#6.8.1</a><br class=""><br class="">  case constant-expression : statement<br class=""><br class="">The statement following the case label is part of the case label.<br class=""><br class="">This differs from the compound statement: <a href="https://cigix.me/c17#6.8.2" class="">https://cigix.me/c17#6.8.2</a> which contains an optional block-item-list which can consistent of multiple statements or declarations:<br class=""><br class=""> block-item-list:<br class="">    block-item<br class="">    block-item-list block-item<br class="">  <br class=""> block-item:<br class="">    declaration<br class="">    statement</div><div class=""><br class=""></div><div class="">I hope this explanation clears it up for you.</div><div class=""><br class=""></div><div class="">Regards</div><div class="">Shafik<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On May 12, 2021, at 11:20 AM, Jacob Faibussowitsch via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello Clang Community,<div class=""><br class=""></div><div class="">Why is the first statement after a “case” label the child of the case label, but every other statement (including the break) after that its sibling? It seems like either all should be children or all should be siblings.</div><div class=""><br class=""></div><div class="">Suppose you have the following code snippet (f<span style="caret-color: rgb(0, 0, 0);" class="">ull source files for any snippets below are included with this mail).</span></div><div class=""><br class=""></div><div class="">switch(expr) {<br class="">  case 1:<br class="">    func1();<br class="">    func2();<br class="">    break;<br class="">  case 2:<br class="">    func1();<br class="">    break;</div><div class="">}<br class=""><br class=""></div><div class="">Which when fed to clang with </div><div class=""><br class=""></div><div class="">$ clang -Xclang -ast-dump -fsyntax-only test.c</div><div class=""><br class=""></div><div class="">produces the following AST  (edited for clarity):</div><div class=""><br class=""></div><div class="">| SwitchStmt <line:7:3, line:15:3><br class="">    | `-CompoundStmt <col:15, line:15:3><br class="">    |   |-CaseStmt <line:8:3, line:9:11><br class="">    |   | `-CallExpr <line:9:5, col:11> —————————— func1() here is child to case 1<br class="">    |   |-CallExpr <line:10:5, col:11> —————————— func2() here is sibling to case 1<br class="">    |   |-BreakStmt <line:11:5><br class="">    |   |-CaseStmt <line:12:3, line:13:11><br class="">    |   | `-CallExpr <line:13:5, col:11> ————————— func1() here again is child to case 2<br class="">    |   `-BreakStmt <line:14:5></div><div class=""><br class=""></div><div class="">My clang version and install info:</div><div class=""><br class=""></div><div class="">Apple clang version 12.0.5 (clang-1205.0.22.9)<br class="">Target: x86_64-apple-darwin20.4.0<br class="">Thread model: posix<br class="">InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin</div><div class=""><br class=""></div><div class=""><div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Best regards,<br class=""><br class="">Jacob Faibussowitsch<br class="">(Jacob Fai - booss - oh - vitch)<br class=""></div></div></div>
</div>
</div></div><span id="cid:446665B2-ABEA-4EF9-A9A5-CC2181851228"><test.c></span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div class=""></div></div><span id="cid:67E8065A-8B91-45EF-8023-54966176AB6D"><astDump.out></span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div class=""></div></div><span id="cid:FAAE6E20-B3A9-491A-A2F8-DB3F7AF0BA1A"><astDumpNoColor.txt></span><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""></div></div>_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></div></body></html>