[llvm-commits] [llvm] r51831 - /llvm/trunk/docs/CodingStandards.html

Nick Lewycky nicholas at mxc.ca
Sat May 31 16:54:55 PDT 2008


Author: nicholas
Date: Sat May 31 18:54:55 2008
New Revision: 51831

URL: http://llvm.org/viewvc/llvm-project?rev=51831&view=rev
Log:
Add a standard for control-flow unreachable assertions in functions that return
values, so as to avoid warnings on some platforms.

Modified:
    llvm/trunk/docs/CodingStandards.html

Modified: llvm/trunk/docs/CodingStandards.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CodingStandards.html?rev=51831&r1=51830&r2=51831&view=diff

==============================================================================
--- llvm/trunk/docs/CodingStandards.html (original)
+++ llvm/trunk/docs/CodingStandards.html Sat May 31 18:54:55 2008
@@ -623,6 +623,29 @@
 
 <p>You get the idea...</p>
 
+<p>Please be aware when adding assert statements that not all compilers are aware of
+the semantics of the assert.  In some places, asserts are used to indicate a piece of
+code that should not be reached.  These are typically of the form:</p>
+
+<div class="doc_code">
+<pre>
+assert(0 && "Some helpful error message");
+</pre>
+</div>
+
+<p>When used in a function that returns a value, they should be followed with a return
+statement and a comment indicating that this line is never reached.  This will prevent
+a compiler which is unable to deduce that the assert statement never returns from
+generating a warning.</p>
+
+<div class="doc_code">
+<pre>
+assert(0 && "Some helpful error message");
+// Not reached
+return 0;
+</pre>
+</div>
+
 </div>
 
 <!-- _______________________________________________________________________ -->





More information about the llvm-commits mailing list