CodingGuidelines: allow declaring variables in for loops

Since 44ba10d6712 (revision: use C99 declaration of variable in for() loop, 2021-11-14) released with v2.35.0 we've had a variable declared with in a for loop. Since then we've had inadvertent follow-ups to that with at least cb2607759e2 (merge-ort: store more specific conflict information, 2022-06-18) released with v2.38.0. As November 2022 is within the window of this upcoming release, let's update the guideline to allow this. We can have the promised "revisit" discussion while this patch cooks, and drop it if it turns out that it is still premature, which is not expected to happen at this moment. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Oct 10, 2022 at 13:37 UTC 82dd01d81b1babf6714435b80683e756de1a4d64
2 files changed +2 -15
Documentation/CodingGuidelines
+2 -8
@@ -232,18 +232,12 @@ For C programs:
232 . since early 2021 with 765dc168882, we have been using variadic
233 macros, mostly for printf-like trace and debug macros.
234
235 - These used to be forbidden, but we have not heard any breakage
236 - report, and they are assumed to be safe.
235 + . since late 2021 with 44ba10d6, we have had variables declared in
236 + the for loop "for (int i = 0; i < 10; i++)".
237
238 - Variables have to be declared at the beginning of the block, before
239 the first statement (i.e. -Wdeclaration-after-statement).
240
241 - - Declaring a variable in the for loop "for (int i = 0; i < 10; i++)"
242 - is still not allowed in this codebase. We are in the process of
243 - allowing it by waiting to see that 44ba10d6 (revision: use C99
244 - declaration of variable in for() loop, 2021-11-14) does not get
245 - complaints. Let's revisit this around November 2022.
246 -
241 - NULL pointers shall be written as NULL, not as 0.
242
243 - When declaring pointers, the star sides with the variable
revision.c
-7
@@ -47,13 +47,6 @@ static inline int want_ancestry(const struct rev_info *revs);
47 void show_object_with_name(FILE *out, struct object *obj, const char *name)
48 {
49 fprintf(out, "%s ", oid_to_hex(&obj->oid));
50 - /*
51 - * This "for (const char *p = ..." is made as a first step towards
52 - * making use of such declarations elsewhere in our codebase. If
53 - * it causes compilation problems on your platform, please report
54 - * it to the Git mailing list at git@vger.kernel.org. In the meantime,
55 - * adding -std=gnu99 to CFLAGS may help if you are with older GCC.
56 - */
50 for (const char *p = name; *p && *p != '\n'; p++)
51 fputc(*p, out);
52 fputc('\n', out);