diff options
author | Chris Lattner <sabre@nondot.org> | 2009-07-28 22:54:04 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-07-28 22:54:04 +0000 |
commit | 14abb832b277b845625d1960ca3129bf7faaa52f (patch) | |
tree | 76f64fa48588cb5cfffb80c6d8312e3037874f48 /llvm/docs | |
parent | a58b3af8027c6780e4aba35f76419b4eca81449a (diff) | |
download | bcm5719-llvm-14abb832b277b845625d1960ca3129bf7faaa52f.tar.gz bcm5719-llvm-14abb832b277b845625d1960ca3129bf7faaa52f.zip |
discourage else after "noreturn" statements.
llvm-svn: 77387
Diffstat (limited to 'llvm/docs')
-rw-r--r-- | llvm/docs/CodingStandards.html | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/llvm/docs/CodingStandards.html b/llvm/docs/CodingStandards.html index f66a7c2154e..2fe3bdc9e2b 100644 --- a/llvm/docs/CodingStandards.html +++ b/llvm/docs/CodingStandards.html @@ -43,6 +43,8 @@ Private</a></li> <li><a href="#hl_earlyexit">Use Early Exits and 'continue' to Simplify Code</a></li> + <li><a href="#hl_else_after_return">Don't use "else" after a + return</a></li> <li><a href="#hl_predicateloops">Turn Predicate Loops into Predicate Functions</a></li> </ol></li> @@ -624,6 +626,88 @@ be a big understandability win.</p> </div> +<!-- _______________________________________________________________________ --> +<div class="doc_subsubsection"> + <a name="hl_else_after_return">Don't use "else" after a return</a> +</div> + +<div class="doc_text"> + +<p>For similar reasons above (reduction of indentation and easier reading), + please do not use "else" or "else if" after something that interrupts + control flow like return, break, continue, goto, etc. For example, this is + "bad":</p> + +<div class="doc_code"> +<pre> + case 'J': { + if (Signed) { + Type = Context.getsigjmp_bufType(); + if (Type.isNull()) { + Error = ASTContext::GE_Missing_sigjmp_buf; + return QualType(); + } else { + break; + } + } else { + Type = Context.getjmp_bufType(); + if (Type.isNull()) { + Error = ASTContext::GE_Missing_jmp_buf; + return QualType(); + } else { + break; + } + } + } + } +</pre> +</div> + +<p>It is better to write this something like:</p> + +<div class="doc_code"> +<pre> + case 'J': + if (Signed) { + Type = Context.getsigjmp_bufType(); + if (Type.isNull()) { + Error = ASTContext::GE_Missing_sigjmp_buf; + return QualType(); + } + } else { + Type = Context.getjmp_bufType(); + if (Type.isNull()) { + Error = ASTContext::GE_Missing_jmp_buf; + return QualType(); + } + } + break; +</pre> +</div> + +<p>Or better yet (in this case), as:</p> + +<div class="doc_code"> +<pre> + case 'J': + if (Signed) + Type = Context.getsigjmp_bufType(); + else + Type = Context.getjmp_bufType(); + + if (Type.isNull()) { + Error = Signed ? ASTContext::GE_Missing_sigjmp_buf : + ASTContext::GE_Missing_jmp_buf; + return QualType(); + } + break; +</pre> +</div> + +<p>The idea is to reduce indentation and the amount of code you have to keep + track of when reading the code.</p> + +</div> <!-- _______________________________________________________________________ --> <div class="doc_subsubsection"> |