]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
scripts/checkpatch: ignore spaces required around some operators in C++
authorPierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Mon, 15 Jun 2026 19:35:23 +0000 (12:35 -0700)
committerPierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Tue, 16 Jun 2026 17:59:05 +0000 (10:59 -0700)
C++ has a different style when it comes to space around references,
dereferences, so don't report it.
Also, closing templates with >> gets wrongly confused with >> operator,
so just relax this check.

Some examples:
ERROR: spaces required around that '&' (ctx:WxV)
+                auto &[counter, p] = *static_cast<TbData*>(udata);
                      ^

ERROR: spaces required around that '*' (ctx:VxO)
+                auto &[counter, p] = *static_cast<TbData*>(udata);
                                                         ^

ERROR: spaces required around that '>>' (ctx:VxW)
+        std::vector<std::pair<Vaddr, uint64_t>> v;                                              ^

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Link: https://lore.kernel.org/qemu-devel/20260615193526.2883349-25-pierrick.bouvier@oss.qualcomm.com
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
scripts/checkpatch.pl

index 2189db19f5402a36253b134986eb8171f591493e..538e059e2653986eb94d0df8f7b309fc969ebfeb 100755 (executable)
@@ -2621,6 +2621,31 @@ sub process {
                                                if ($op eq '::') {
                                                        $ok = 1;
                                                }
+
+                                               # Ignore * in C++: templates and
+                                               # pointer types are incorrectly
+                                               # flagged. Example:
+                                               # static_cast<T*>
+                                               if ($op eq '*') {
+                                                       $ok = 1;
+                                               }
+
+                                               # Ignore & in C++: & means a
+                                               # reference, and this create
+                                               # issues with some constructions.
+                                               # Example:
+                                               # auto &[first, second] = pair;
+                                               if ($op eq '&') {
+                                                       $ok = 1;
+                                               }
+
+                                               # Ignore >> in C++
+                                               # checkpatch is confused by
+                                               # >> closing templates. Example:
+                                               # vector<pair<A, B>>
+                                               if ($op eq '>>') {
+                                                       $ok = 1;
+                                               }
                                        }
 
                                        # Ignore email addresses <foo@bar>