<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Ericsson Hilda";
        panose-1:0 0 5 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Ericsson Hilda",serif;
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal-compose;
        font-family:"Ericsson Hilda",serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=SV link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'>I also prefer to always use braces even when not strictly necessary, for the same reasons as already mentioned. The only situation where I personally choose to remove the braces is when the statement fits on the same line as the condition, e.g.:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:65.2pt'><span lang=EN-US style='font-family:"Courier New",serif;mso-fareast-language:EN-US'>if (cond) statement;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'>In such cases, I find it clear that I need to add braces when expanding the statements.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'>But in case we want to be on the safe side I vote for always including braces, no matter what.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'>Gabriel <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Ericsson Hilda",serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><b><span lang=EN-US>From:</span></b><span lang=EN-US> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of </b>James Henderson via llvm-dev<br><b>Sent:</b> den 16 juni 2020 10:02<br><b>To:</b> Matt Arsenault <arsenm2@gmail.com><br><b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org><br><b>Subject:</b> Re: [llvm-dev] Codifying our Brace rules-<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>I'm with Matt on this one. I much prefer the approach of ALWAYS use braces for ifs and for loops, even if they're not needed, for basically the same reasons as he put. The number of times I've added a statement inside an if without braces and forget to add them is annoyingly high, especially as it's not always an obvious error upfront. Similarly, being involved in a downstream codebase with several private patches, having to sometimes add the braces makes merges all the harder and sometimes more dangerous.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I doubt we're going to get the policy changed from "don't include unnecessary braces for trivial statements" but if there's any style that adds them in more places, I'm up for that.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>James<o:p></o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>On Mon, 15 Jun 2020 at 20:56, Matt Arsenault via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm'><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><br><br><o:p></o:p></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal>On Jun 15, 2020, at 15:46, Keane, Erich via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><div><p class=MsoNormal>Hi all-<o:p></o:p></p></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal>A few weeks ago I noticed that our “omit braces with single line blocks” rule wasn’t written down!  Additionally, as a group on IRC and in review, noticed that the enforcement of this rule has been extremely inconsistent.  We made a first run at codifying our existing practice here: <a href="https://protect2.fireeye.com/v1/url?k=9efa459c-c04ad804-9efa0507-861fcb972bfc-42265df8dd683c0d&q=1&e=1cccb19d-3ee2-420f-b3a4-89ab398de655&u=https%3A%2F%2Freviews.llvm.org%2FD80947" target="_blank"><span style='color:#954F72'>https://reviews.llvm.org/D80947</span></a>, which was then committed after significant time on llvm-commits.<o:p></o:p></p></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal>I would like to encourage the list via discussion and further reviews/commits to come to a consensus on what we actually MEAN by this rule.  For example, a recent comment points out that :<o:p></o:p></p></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal>If (cond)<o:p></o:p></p></div><div><p class=MsoNormal>  Stmt;<o:p></o:p></p></div><div><p class=MsoNormal>else if (cond)<o:p></o:p></p></div><div><p class=MsoNormal>  Stmt;<o:p></o:p></p></div><div><p class=MsoNormal>else {<o:p></o:p></p></div><div><p class=MsoNormal>  Stmt;<o:p></o:p></p></div><div><p class=MsoNormal>  Stmt;<o:p></o:p></p></div><div><p class=MsoNormal>}<o:p></o:p></p></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal>Should require braces on all of the conditions!  However, we are extraordinarily inconsistent here.  My wish is for us to become more consistent, so I would like us to use this thread to organize our collective thoughts on figuring out what the rule actually SHOULD be, and organizing a handful of commits to the coding standard to make sure it says what we mean.<o:p></o:p></p></div><div><p class=MsoNormal><br>Thanks,<br>Erich<o:p></o:p></p></div></div></div></blockquote><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I think braces should be added in all contexts, and the more contexts the better. It eliminates any inconsistency or attempt to contextually interpret rules. It also reduces merge conflicts, since something eventually something will probably be added inside any control flow statement. I’ve suffered through many painful merges trying to find where the braces went wrong, usually due to switch statements. The sometimes-braces-sometimes-not combined with the lack of indentation for switch cases leads to way more time figuring out braces than should be necessary.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>-Matt<o:p></o:p></p></div></div><p class=MsoNormal>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="https://protect2.fireeye.com/v1/url?k=90b9cffd-ce095265-90b98f66-861fcb972bfc-e3caea4c1054abaf&q=1&e=1cccb19d-3ee2-420f-b3a4-89ab398de655&u=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p></blockquote></div></div></body></html>