diff options
author | Eric Blake <eblake@redhat.com> | 2014-09-03 16:18:19 -0600 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2014-09-04 15:38:00 -0600 |
commit | bc7e63d39ca0e96073ba04e5a0c2b5471ca05b85 (patch) | |
tree | 89c5ea5e85b2168970435863d4504dbd8cb79e5d /HACKING | |
parent | 625e04a86e79c9bcf5bb29c942b65b19c1d09dbb (diff) | |
download | libvirt-bc7e63d39ca0e96073ba04e5a0c2b5471ca05b85.tar.gz |
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>
Diffstat (limited to 'HACKING')
-rw-r--r-- | HACKING | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -461,6 +461,33 @@ But if negating a complex condition is too ugly, then at least add braces: x = y; } +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. + + 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; + } + } + } + Preprocessor ============ |