{"thread":{"id":"48932","subject":"[PATCH] Makefile: add a DEVOPTS flag to get pedantic compilation","startedAt":"2018-07-21T18:59:41Z","lastAt":"2018-07-23T18:51:59Z","messageCount":3,"participants":["Beat Bolli","Ævar Arnfjörð Bjarmason","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"353250","messageId":"20180721185933.32377-1-dev+git@drbeat.li","threadId":"48932","inReplyTo":null,"subject":"[PATCH] Makefile: add a DEVOPTS flag to get pedantic compilation","fromName":"Beat Bolli","fromEmail":"dev+git@drbeat.li","sentAt":"2018-07-21T18:59:33Z","receivedAt":"2018-07-21T18:59:41Z","isPatch":true,"sender":{"key":"dev+git@drbeat.li","avatar":"https://avatars.githubusercontent.com/u/21444?v=4"},"body":"In the interest of code hygiene, make it easier to compile Git with the\nflag -pedantic.\n\nPure pedantic compilation results in one warning per use of the\ntranslation macro `N_`, therefore also disable the parenthesising of\ni18n strings with -DUSE_PARENS_AROUND_GETTEXT_N=0 to show only real\nwarnings.\n\nSigned-off-by: Beat Bolli <dev+git@drbeat.li>\n---\n\nThis is the convenience knob for all developers that led to the series\nbb/pedantic[1]. It does not depend on this series, though.\n\n[1] https://public-inbox.org/git/20180708144342.11922-1-dev+git@drbeat.li/T/#u\n\n Makefile       | 4 ++++\n config.mak.dev | 4 ++++\n 2 files changed, 8 insertions(+)\n\ndiff --git a/Makefile b/Makefile\nindex 0cb6590f24..f800054379 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -484,6 +484,10 @@ all::\n #        The DEVELOPER mode enables -Wextra with a few exceptions. By\n #        setting this flag the exceptions are removed, and all of\n #        -Wextra is used.\n+#\n+#    pedantic:\n+#\n+#        Enable -pedantic compilation.\n \n GIT-VERSION-FILE: FORCE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\ndiff --git a/config.mak.dev b/config.mak.dev\nindex 2d244ca470..f21f0d0209 100644\n--- a/config.mak.dev\n+++ b/config.mak.dev\n@@ -1,6 +1,10 @@\n ifeq ($(filter no-error,$(DEVOPTS)),)\n CFLAGS += -Werror\n endif\n+ifneq ($(filter pedantic,$(DEVOPTS)),)\n+CFLAGS += -pedantic\n+# don't warn for each N_ use\n+CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0\n+endif\n CFLAGS += -Wdeclaration-after-statement\n CFLAGS += -Wno-format-zero-length\n CFLAGS += -Wold-style-definition\n-- \n2.18.0.203.gfac676dfb9\n\n"},{"id":"353252","messageId":"87wotobclv.fsf@evledraar.gmail.com","threadId":"48932","inReplyTo":"20180721185933.32377-1-dev+git@drbeat.li","subject":"Re: [PATCH] Makefile: add a DEVOPTS flag to get pedantic compilation","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-07-21T19:41:32Z","receivedAt":"2018-07-21T19:41:37Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sat, Jul 21 2018, Beat Bolli wrote:\n\n> In the interest of code hygiene, make it easier to compile Git with the\n> flag -pedantic.\n>\n> Pure pedantic compilation results in one warning per use of the\n> translation macro `N_`, therefore also disable the parenthesising of\n> i18n strings with -DUSE_PARENS_AROUND_GETTEXT_N=0 to show only real\n> warnings.\n\nI like this...\n\n> diff --git a/Makefile b/Makefile\n> index 0cb6590f24..f800054379 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -484,6 +484,10 @@ all::\n>  #        The DEVELOPER mode enables -Wextra with a few exceptions. By\n>  #        setting this flag the exceptions are removed, and all of\n>  #        -Wextra is used.\n> +#\n> +#    pedantic:\n> +#\n> +#        Enable -pedantic compilation.\n\nBut let's mention that we toggle USE_PARENS_AROUND_GETTEXT_N implicitly\nwhen this is set here.\n\n> +CFLAGS += -pedantic\n> +# don't warn for each N_ use\n> +CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0\n> +endif\n\n...and set this to \"no\" not \"0\" since we document that that's the way to\ntoggle it off in the Makefile, i.e. let's be consistent.\n\nAlso, it would be helpful for future digging if the commit message\nmentioned which -W flag included in -Wpedantic is triggering this\nUSE_PARENS_AROUND_GETTEXT_N condition that previously wasn't triggered,\nand on which compiler & version. 290c8e7a3f (\"gettext.h: add parentheses\naround N_ expansion if supported\", 2015-01-11) doesn't mention anything\nlike that.\n"},{"id":"353397","messageId":"xmqqzhyh6b05.fsf@gitster-ct.c.googlers.com","threadId":"48932","inReplyTo":"87wotobclv.fsf@evledraar.gmail.com","subject":"Re: [PATCH] Makefile: add a DEVOPTS flag to get pedantic compilation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-07-23T18:51:54Z","receivedAt":"2018-07-23T18:51:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n>> +CFLAGS += -pedantic\n>> +# don't warn for each N_ use\n>> +CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0\n>> +endif\n>\n> ...and set this to \"no\" not \"0\" since we document that that's the way to\n> toggle it off in the Makefile, i.e. let's be consistent.\n\nThe Make variable USE_PARENS_AROUND_GETTEXT_N is described as taking\n\"yes\" or \"no\".\n\n    # Define USE_PARENS_AROUND_GETTEXT_N to \"yes\" if your compiler happily\n    # compiles the following initialization:\n    #\n    #   static const char s[] = (\"FOO\");\n    #\n    # and define it to \"no\" if you need to remove the parentheses () around the\n    # constant.  The default is \"auto\", which means to use parentheses if your\n    # compiler is detected to support it.\n\nBut the knob on the CFLAGS set by these variables take 1 or 0\n\n    ifeq (yes,$(USE_PARENS_AROUND_GETTEXT_N))\n            BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=1\n    else\n    ifeq (no,$(USE_PARENS_AROUND_GETTEXT_N))\n            BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0\n    endif\n    endif\n\nAnd the code that uses the CFLAGS knob \n\n    /* Mark msgid for translation but do not translate it. */\n    #if !USE_PARENS_AROUND_GETTEXT_N\n    #define N_(msgid) msgid\n    #else\n    ...\n    #define N_(msgid) (msgid)\n    #endif\n\npays attention to the truth/false in usual C preprocessor sense.\nYour \"no\" happens to serve as 0 just like \"yes\" would.\n\nSo I think you suggestion is a bad one that makes a misleading\nresult.\n\n[Footnote]\n\n*1* The following shows all \"not X\" except for \"not one\".\n\n#include <stdio.h>\n\n#define ZERO 0\n#define ONE 1\n#define YES yes\n#define NO no\n#undef UNDEF\n\nconst char *msgs[] = {\n#if !ZERO\n\t\"not zero\",\n#endif\n#if !ONE\n\t\"not one\",\n#endif\n#if !YES\n\t\"not yes\",\n#endif\n#if !NO\n\t\"not no\",\n#endif\n#if !UNDEF\n\t\"not undef\",\n#endif\n\tNULL\n};\n\nint main(int ac, char **av)\n{\n\tconst char **cp = msgs;\n\n\twhile (*cp) {\n\t\tprintf(\"%s\\n\", *cp);\n\t\tcp++;\n\t}\n\treturn 0;\n}\n\n\n\n\n"}]}