git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Makefile: add a DEVOPTS flag to get pedantic compilation
@ 2018-07-21 18:59 Beat Bolli
  2018-07-21 19:41 ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 3+ messages in thread
From: Beat Bolli @ 2018-07-21 18:59 UTC (permalink / raw)
  To: git; +Cc: gitster, Beat Bolli

In the interest of code hygiene, make it easier to compile Git with the
flag -pedantic.

Pure pedantic compilation results in one warning per use of the
translation macro `N_`, therefore also disable the parenthesising of
i18n strings with -DUSE_PARENS_AROUND_GETTEXT_N=0 to show only real
warnings.

Signed-off-by: Beat Bolli <dev+git@drbeat.li>
---

This is the convenience knob for all developers that led to the series
bb/pedantic[1]. It does not depend on this series, though.

[1] https://public-inbox.org/git/20180708144342.11922-1-dev+git@drbeat.li/T/#u

 Makefile       | 4 ++++
 config.mak.dev | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/Makefile b/Makefile
index 0cb6590f24..f800054379 100644
--- a/Makefile
+++ b/Makefile
@@ -484,6 +484,10 @@ all::
 #        The DEVELOPER mode enables -Wextra with a few exceptions. By
 #        setting this flag the exceptions are removed, and all of
 #        -Wextra is used.
+#
+#    pedantic:
+#
+#        Enable -pedantic compilation.
 
 GIT-VERSION-FILE: FORCE
 	@$(SHELL_PATH) ./GIT-VERSION-GEN
diff --git a/config.mak.dev b/config.mak.dev
index 2d244ca470..f21f0d0209 100644
--- a/config.mak.dev
+++ b/config.mak.dev
@@ -1,6 +1,10 @@
 ifeq ($(filter no-error,$(DEVOPTS)),)
 CFLAGS += -Werror
 endif
+ifneq ($(filter pedantic,$(DEVOPTS)),)
+CFLAGS += -pedantic
+# don't warn for each N_ use
+CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
+endif
 CFLAGS += -Wdeclaration-after-statement
 CFLAGS += -Wno-format-zero-length
 CFLAGS += -Wold-style-definition
-- 
2.18.0.203.gfac676dfb9


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Makefile: add a DEVOPTS flag to get pedantic compilation
  2018-07-21 18:59 [PATCH] Makefile: add a DEVOPTS flag to get pedantic compilation Beat Bolli
@ 2018-07-21 19:41 ` Ævar Arnfjörð Bjarmason
  2018-07-23 18:51   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-07-21 19:41 UTC (permalink / raw)
  To: Beat Bolli; +Cc: git, gitster


On Sat, Jul 21 2018, Beat Bolli wrote:

> In the interest of code hygiene, make it easier to compile Git with the
> flag -pedantic.
>
> Pure pedantic compilation results in one warning per use of the
> translation macro `N_`, therefore also disable the parenthesising of
> i18n strings with -DUSE_PARENS_AROUND_GETTEXT_N=0 to show only real
> warnings.

I like this...

> diff --git a/Makefile b/Makefile
> index 0cb6590f24..f800054379 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -484,6 +484,10 @@ all::
>  #        The DEVELOPER mode enables -Wextra with a few exceptions. By
>  #        setting this flag the exceptions are removed, and all of
>  #        -Wextra is used.
> +#
> +#    pedantic:
> +#
> +#        Enable -pedantic compilation.

But let's mention that we toggle USE_PARENS_AROUND_GETTEXT_N implicitly
when this is set here.

> +CFLAGS += -pedantic
> +# don't warn for each N_ use
> +CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
> +endif

...and set this to "no" not "0" since we document that that's the way to
toggle it off in the Makefile, i.e. let's be consistent.

Also, it would be helpful for future digging if the commit message
mentioned which -W flag included in -Wpedantic is triggering this
USE_PARENS_AROUND_GETTEXT_N condition that previously wasn't triggered,
and on which compiler & version. 290c8e7a3f ("gettext.h: add parentheses
around N_ expansion if supported", 2015-01-11) doesn't mention anything
like that.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Makefile: add a DEVOPTS flag to get pedantic compilation
  2018-07-21 19:41 ` Ævar Arnfjörð Bjarmason
@ 2018-07-23 18:51   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2018-07-23 18:51 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Beat Bolli, git

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

>> +CFLAGS += -pedantic
>> +# don't warn for each N_ use
>> +CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
>> +endif
>
> ...and set this to "no" not "0" since we document that that's the way to
> toggle it off in the Makefile, i.e. let's be consistent.

The Make variable USE_PARENS_AROUND_GETTEXT_N is described as taking
"yes" or "no".

    # Define USE_PARENS_AROUND_GETTEXT_N to "yes" if your compiler happily
    # compiles the following initialization:
    #
    #   static const char s[] = ("FOO");
    #
    # and define it to "no" if you need to remove the parentheses () around the
    # constant.  The default is "auto", which means to use parentheses if your
    # compiler is detected to support it.

But the knob on the CFLAGS set by these variables take 1 or 0

    ifeq (yes,$(USE_PARENS_AROUND_GETTEXT_N))
            BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=1
    else
    ifeq (no,$(USE_PARENS_AROUND_GETTEXT_N))
            BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
    endif
    endif

And the code that uses the CFLAGS knob 

    /* Mark msgid for translation but do not translate it. */
    #if !USE_PARENS_AROUND_GETTEXT_N
    #define N_(msgid) msgid
    #else
    ...
    #define N_(msgid) (msgid)
    #endif

pays attention to the truth/false in usual C preprocessor sense.
Your "no" happens to serve as 0 just like "yes" would.

So I think you suggestion is a bad one that makes a misleading
result.

[Footnote]

*1* The following shows all "not X" except for "not one".

#include <stdio.h>

#define ZERO 0
#define ONE 1
#define YES yes
#define NO no
#undef UNDEF

const char *msgs[] = {
#if !ZERO
	"not zero",
#endif
#if !ONE
	"not one",
#endif
#if !YES
	"not yes",
#endif
#if !NO
	"not no",
#endif
#if !UNDEF
	"not undef",
#endif
	NULL
};

int main(int ac, char **av)
{
	const char **cp = msgs;

	while (*cp) {
		printf("%s\n", *cp);
		cp++;
	}
	return 0;
}





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-23 18:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-21 18:59 [PATCH] Makefile: add a DEVOPTS flag to get pedantic compilation Beat Bolli
2018-07-21 19:41 ` Ævar Arnfjörð Bjarmason
2018-07-23 18:51   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).