]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
build: syntax check to avoid 'const fooPtr'
authorEric Blake <eblake@redhat.com>
Tue, 24 Sep 2013 16:41:54 +0000 (10:41 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 14 Oct 2013 20:37:26 +0000 (14:37 -0600)
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can).  But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).

Now that the code base has been cleaned, enforce it with a syntax
checker.

* cfg.mk (sc_forbid_const_pointer_typedef): New rule.

Signed-off-by: Eric Blake <eblake@redhat.com>
cfg.mk

diff --git a/cfg.mk b/cfg.mk
index dad8a9070f16206b18eb22831097ab6999f1e2d3..3e44439dfd6a87b2947358a19cf7357fcf3ee6e0 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -468,6 +468,14 @@ sc_correct_id_types:
        halt="use pid_t for pid, uid_t for uid, gid_t for gid"          \
          $(_sc_search_regexp)
 
+# "const fooPtr a" is the same as "foo * const a", even though it is
+# usually desired to have "foo const *a".  It's easier to just prevent
+# the confusing mix of typedef vs. const placement.
+sc_forbid_const_pointer_typedef:
+       @prohibit='(^|[^"])const \w*Ptr'                                \
+       halt='"const fooPtr var" does not declare what you meant'       \
+         $(_sc_search_regexp)
+
 # Forbid sizeof foo or sizeof (foo), require sizeof(foo)
 sc_size_of_brackets:
        @prohibit='sizeof\s'                                            \