mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
maint: tighten curly brace syntax checking
Now that hanging brace offenders have been fixed, we can automate the check, and document our style. Done as a separate commit from code changes, to make it easier to just backport code changes, if that is ever needed. * cfg.mk (sc_curly_braces_style): Catch hanging braces. * docs/hacking.html.in: Document it. * HACKING: Regenerate. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
@@ -593,6 +593,37 @@
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>Use hanging braces for compound statements: the opening brace
|
||||
of a compound statement should be on the same line as the
|
||||
condition being tested. Only top-level function bodies, nested
|
||||
scopes, and compound structure declarations should ever have {
|
||||
on a line by itself.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
void
|
||||
foo(int a, int b)
|
||||
{ // correct - function body
|
||||
int 2d[][] = {
|
||||
{ // correct - complex initialization
|
||||
1, 2,
|
||||
},
|
||||
};
|
||||
if (a)
|
||||
{ // BAD: compound brace on its own line
|
||||
do_stuff();
|
||||
}
|
||||
{ // correct - nested scope
|
||||
int tmp;
|
||||
if (a < b) { // correct - hanging brace
|
||||
tmp = b;
|
||||
b = a;
|
||||
a = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h2><a name="preprocessor">Preprocessor</a></h2>
|
||||
|
||||
<p>Macros defined with an ALL_CAPS name should generally be
|
||||
|
||||
Reference in New Issue
Block a user