On Wed, Apr 25, 2018 at 03:25:07PM +0200, Martin Kletzander wrote:
Let's make a rule out of it and document it.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
cfg.mk | 6 ++++++
docs/hacking.html.in | 9 +++++++++
2 files changed, 15 insertions(+)
diff --git a/cfg.mk b/cfg.mk
index 902178dd1c3a..5f75338aac04 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1050,6 +1050,12 @@ sc_prohibit_backslash_alignment:
halt='Do not attempt to right-align backslashes' \
$(_sc_search_regexp)
+sc_prohibit_space_after_cast:
+ @prohibit='(\([a-zA-Z _]+ \*+
Both this
|\(((signed|unsigned|long|short|int|char|
[a-zA-Z]+_t
and this should include numbers to catch types like uint64_t
|void|struct) ?)+|switch \(\(vir[a-zA-Z]*Type)\)[[:space:]]+
([^ );,{=\\A-Z])' \
Allowing 'A-Z' here misses some cases of casting NULL and some macros.
The false positives include function declarations from vbox_CAPI header
files and our one-line helpers with no arguments and some ATTRIBUTE_
marker.
Since any attempts to parse C with a regex will have some limitations,
I'd just drop 'void' from the list of types in the first part, since
we don't need to use it that often - only the hal driver and the
viratomic macros use it as ignore_value.
Jano
+ in_vc_files='*\.[chx]$$' \
+ halt='Do not use space after cast' \
+ $(_sc_search_regexp)
+
# We don't use this feature of maint.mk.
prev_version_file = /dev/null
diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index fbeea3eb751d..bf6f80c0d217 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -579,6 +579,15 @@
int foo(int wizz); // Good
</pre>
+ <p>
+ There must not be any whitespace immediately following a cast to any
+ type. E.g.
+ </p>
+ <pre>
+ foo = (int) bar; // Bad
+ foo = (int)bar; // Good
+</pre>
+
<h2><a id="comma">Commas</a></h2>
<p>
--
2.17.0
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list