diff options
Diffstat (limited to 'docs/CodingStandards.html')
-rw-r--r-- | docs/CodingStandards.html | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/docs/CodingStandards.html b/docs/CodingStandards.html index 7815e19..416c29b 100644 --- a/docs/CodingStandards.html +++ b/docs/CodingStandards.html @@ -249,7 +249,7 @@ order:</p> <li><tt>llvm/*</tt></li> <li><tt>llvm/Analysis/*</tt></li> <li><tt>llvm/Assembly/*</tt></li> - <li><tt>llvm/Bytecode/*</tt></li> + <li><tt>llvm/Bitcode/*</tt></li> <li><tt>llvm/CodeGen/*</tt></li> <li>...</li> <li><tt>Support/*</tt></li> @@ -851,6 +851,38 @@ return 0; </pre> </div> +<p>Another issue is that values used only by assertions will produce an "unused + value" warning when assertions are disabled. For example, this code will warn: +</p> + +<div class="doc_code"> +<pre> + unsigned Size = V.size(); + assert(Size > 42 && "Vector smaller than it should be"); + + bool NewToSet = Myset.insert(Value); + assert(NewToSet && "The value shouldn't be in the set yet"); +</pre> +</div> + +<p>These are two interesting different cases: in the first case, the call to +V.size() is only useful for the assert, and we don't want it executed when +assertions are disabled. Code like this should move the call into the assert +itself. In the second case, the side effects of the call must happen whether +the assert is enabled or not. In this case, the value should be cast to void +to disable the warning. To be specific, it is preferred to write the code +like this:</p> + +<div class="doc_code"> +<pre> + assert(V.size() > 42 && "Vector smaller than it should be"); + + bool NewToSet = Myset.insert(Value); (void)NewToSet; + assert(NewToSet && "The value shouldn't be in the set yet"); +</pre> +</div> + + </div> <!-- _______________________________________________________________________ --> |