git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Denton Liu <liu.denton@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 4/3] pack-bitmap.h: fix unused variable warning
Date: Tue, 24 Sep 2019 17:34:08 -0400	[thread overview]
Message-ID: <20190924213408.GD20858@sigill.intra.peff.net> (raw)
In-Reply-To: <a3a3357925cb144deb35b298cbe2796934fa0673.1569315905.git.liu.denton@gmail.com>

On Tue, Sep 24, 2019 at 02:08:53AM -0700, Denton Liu wrote:

> When we ran `make hdr-check`, we got the following warning on Arch Linux:
> 
> 	pack-bitmap.h:20:19: error: ‘BITMAP_IDX_SIGNATURE’ defined but not used [-Werror=unused-const-variable=]
> 	   20 | static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
> 	      |                   ^~~~~~~~~~~~~~~~~~~~
> 	cc1: all warnings being treated as errors
> 
> "Use" the BITMAP_IDX_SIGNATURE variable by making the size of
> bitmap_disk_header.magic equal to the size of BITMAP_IDX_SIGNATURE. An
> alternative was to simply add MAYBE_UNUSED. However, this design was
> chosen because we eliminate the magic number (4) in the process.

Yeah, I think this is a fine fix. Since it's needed in only a few files,
the more usual fix would be to not define it in the header in the first
place. Something like:

  extern const char BITMAP_IDX_SIGNATURE[4];

or whatever. But I think it's nice to keep it all together.

> I'm tacking this patch on since this warning didn't show up until I
> compiled it on gcc 9.1.0.

Curiously, I _don't_ see the warning with gcc 9.2.1. By my reading of
the manpage, this should be triggered by -Wunused-const-variable=2, but
not by "1" (the difference being whether it triggers for stuff in header
files). And only the latter is triggered by -Wall or -Wextra.

But another weirdness is that hdr-check is directly compiling the header
files. So I guess that fools it. But we don't pass any of the extra
diagnostic options there.  Have you put "-Wall" into your $(CC)?

Perhaps a more realistic hdr-check would be:

  {
    echo '#include "git-compat-util.h"'
    echo '#include "$<"'
  } >$*.hcc
  $(QUIET_HDR)$(CC) $(ALL_CFLAGS) -o /dev/null -c -xc $*.hcc

-Peff

  reply	other threads:[~2019-09-24 21:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-23 18:34 [PATCH 0/3] fixes related to `make hdr-check` Denton Liu
2019-09-23 18:34 ` [PATCH 1/3] Makefile: use $(ALL_CFLAGS) in $(HCO) target Denton Liu
2019-09-26 12:49   ` Johannes Schindelin
2019-09-26 17:38     ` Denton Liu
2019-09-26 19:47       ` Johannes Schindelin
2019-09-28  4:59         ` Junio C Hamano
2019-09-23 18:34 ` [PATCH 2/3] apply.h: include missing header Denton Liu
2019-09-23 18:34 ` [PATCH 3/3] promisor-remote.h: " Denton Liu
2019-09-24  9:08 ` [PATCH 4/3] pack-bitmap.h: fix unused variable warning Denton Liu
2019-09-24 21:34   ` Jeff King [this message]
2019-09-24 21:38     ` Jeff King
2019-09-25  8:20 ` [PATCH v2 0/4] fixes related to `make hdr-check` Denton Liu
2019-09-25  8:20   ` [PATCH v2 1/4] apply.h: include missing header Denton Liu
2019-09-25  8:20   ` [PATCH v2 2/4] promisor-remote.h: " Denton Liu
2019-09-25  8:20   ` [PATCH v2 3/4] pack-bitmap.h: remove magic number Denton Liu
2019-09-25  8:21   ` [PATCH v2 4/4] Makefile: emulate compile in $(HCO) target better Denton Liu
2019-10-02 15:41     ` Jeff King
2019-09-26 12:57 ` [PATCH 0/3] fixes related to `make hdr-check` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190924213408.GD20858@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=liu.denton@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).