Subject: cb/pedantic-build-for-developers, POSIX-but-not-C99 and -Wno-pedantic-ms-format

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Tue, 21 Sep 2021 10:44:02 +0200

On Mon, Sep 20 2021, Junio C Hamano wrote:

> * cb/pedantic-build-for-developers (2021-09-03) 3 commits
>   (merged to 'next' on 2021-09-10 at b8df102019)
>  + developer: enable pedantic by default
>  + win32: allow building with pedantic mode enabled
>  + gettext: remove optional non-standard parens in N_() definition
>
>  Update the build procedure to use the "-pedantic" build when
>  DEVELOPER makefile macro is in effect.

With -pedantic one of my WIP branches started erroring on:

    error: ISO C does not support %n$ operand number formats [-Werror=format=]

I.e. complaining about "%m$" instead of "%" in printf formats, it's easy
enough to fix in my case, it's just something I used to de-duplicate a
rather complex format, this makes it C(89|99)-compliant:
    
    -       strbuf_addf(&fmt, "%%s%%s%%s-%%0%1$lud.%%0%1$lud-%%s-%%s-%%s",
    -                   (unsigned long)tmp.len);
    +       strbuf_addf(&fmt, "%%s%%s%%s-%%0%lud.%%0%lud-%%s-%%s-%%s",
    +                   (unsigned long)tmp.len, (unsigned long)tmp.len);

But in general, do we view -pedantic as an implicit endorsement that we
should be using less POSIX and more standard C than we otherwise would?

I may be wrong, but I believe that construct is widely portable, we
don't use it in the main source, but in the po/ files (so anything that
uses git + gettext tests for this already):

    git grep '%\d+\$' -- po