From: Ævar Arnfjörð Bjarmason Date: Mon, 05 Dec 2022 23:12:32 GMT Subject: Re: [PATCH] git-compat-util.h: introduce CALLOC(x) Message-ID: <221206.868rjle7za.gmgdl@evledraar.gmail.com> In-Reply-To: On Mon, Dec 05 2022, Taylor Blau wrote: > On Mon, Dec 05, 2022 at 10:01:11PM +0100, René Scharfe wrote: >> This rule would turn this code: >> >> struct foo *bar = xcalloc(1, sizeof(*bar)); >> int i; >> >> ... into: >> >> struct foo *bar; >> CALLOC(bar); >> int i; >> >> ... which violates the coding guideline to not mix declarations and >> statements (-Wdeclaration-after-statement). > > Yeah, I was wondering about this myself when I wrote this part of the > Coccinelle patch. > > Is there an intelligent way to tell it to put the first statement after > all declarations? I couldn't find anything after a quick scan of the > documentation nor our own patches. We can get that working, but I think it's good to establish some ground rules first: First, when you add *.pending.cocci rules they shouldn't be pseudocode, but things that are too large to apply right now. I think my recent 041df69edd3 (Merge branch 'ab/fewer-the-index-macros', 2022-11-28) is a good example. In this case if I apply the proposed patch and do: make contrib/coccinelle/xcalloc.pending.cocci.patch && patch -p1