bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: Paul Eggert <eggert@cs.ucla.edu>,
	bug-gnulib@gnu.org, Collin Funk <collin.funk1@gmail.com>
Subject: Re: warnings in unit tests
Date: Tue, 30 Apr 2024 00:12:05 +0200	[thread overview]
Message-ID: <7804088.cEBGB3zze1@nimes> (raw)
In-Reply-To: <10c966f9-34aa-40fd-8659-6075098b0006@gmail.com>

Hi Collin,

> > For test cases this is more a judgment call, but I prefer doing either
> > the above or adjusting the warning flags, to ignoring warnings, as the
> > other warnings can be useful at time.
> 
> Yeah, I could see these warnings making it hard to see ones that
> actually matter. Lets see what Bruno thinks.

Different warning policies need to apply in these fours sets code:

1) Code that originates in the package that uses gnulib.
   Example: coreutils/src/*

2) Code from public header files in gnulib/lib/
   Example: lib/vasnprintf.h because module 'vasnprintf' designates this file
   as its public header file.

3) All other code from gnulib/lib/
   Example: lib/argp-namefrob.h which is not a public header file, lib/*.c.

4) All code in gnulib/tests/


Note that different warning policies may contradict each other. For example,
some people want to see a warning for

    int *table = malloc (n * sizeof (int));

because it has an implicit conversion / "lacks a cast". While other people
want to see a warning for

    int *table = (int *) malloc (n * sizeof (int));

because it has a cast and "casts are dubious". It is impossible to satisfy
both of these policies at the same time.


Back to the four sets of code:

1) This warning policy is the responsibility of that package's maintainer,
   obviously.

2) These header files are used in compilation units of the package, with
   CFLAGS or AM_CFLAGS set by the package's maintainer for that package.
   Therefore in these files we need to avoid even -Wundef, -Wvla, and
   other kinds of warnings that we wouldn't enable in our code.

3) The rest of the lib/ code is under our responsibility, not the
   responsibility of a package's maintainer. We try to avoid warnings
   from "reasonable" warning options. More details in the HACKING file.

4) The unit tests are also in our responsibility, not the responsibility
   of a package's maintainer. Here, the primary concern is that is must
   be *easy* to contribute new unit tests. -Wmissing-variable-declarations
   warnings _could_ — as Paul wrote — be avoided by adding an 'extern'
   declaration for each global variable. But this is extra effort that
   would hinder the addition of new unit tests.

> If we decide to follow the coding style you mentioned

No. It must be possible to contribute a unit test with a simple
global variable. Therefore -Wmissing-variable-declarations is not
adequate for unit tests.

Collin, if you want to find relevant findings in the unit tests, by
using gcc or clang warning options, do *not* use a coreutils build
for this purpose, but a gnulib testdir instead. (Because the latter
is not biased by coding style preferences of any package maintainer.)

Or if you really want to use a coreutils build, first update the
GL_CFLAG_GNULIB_WARNINGS definition in m4/gnulib-common.m4, so that
it eliminates useless kinds of warnings.

Bruno





  reply	other threads:[~2024-04-29 22:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-28  6:52 Pacify -Wmissing-variable-declarations in unit tests Collin Funk
2024-04-28 10:11 ` Bruno Haible
2024-04-28 11:03   ` Collin Funk
2024-04-28 23:27     ` Paul Eggert
2024-04-29  0:58       ` Collin Funk
2024-04-29 22:12         ` Bruno Haible [this message]
2024-04-30  0:31           ` warnings " Collin Funk
  -- strict thread matches above, loose matches on Subject: below --
2021-05-16 17:01 new module 'sigsegv' Bruno Haible
2021-06-07 10:29 ` Dmitry V. Levin
2021-06-08  1:45   ` Jim Meyering
2021-06-08  2:40     ` warnings in unit tests Bruno Haible
2021-06-08  5:55       ` Jim Meyering
2021-06-08  8:56         ` Bruno Haible
2021-06-09  0:41           ` Dmitry V. Levin
2021-06-10 20:05             ` Bruno Haible
     [not found]         ` <CAH8yC8kHTq5J9onJj+2jwy_DwzXrwujqFs9TEBxGh5k_KCu=kg@mail.gmail.com>
2021-06-08 10:57           ` Bruno Haible
2021-06-08 16:42             ` Paul Eggert
2021-06-09 13:35               ` Dmitry V. Levin
2021-06-09 19:38               ` Bruno Haible
2021-06-10 19:39               ` Bruno Haible
2021-06-09  7:23             ` Bernhard Voelker
2021-06-09 14:17               ` Bruno Haible
2021-06-10  8:13                 ` Simon Josefsson via Gnulib discussion list
2021-06-10 19:51                   ` Bruno Haible
2021-06-10 21:49                     ` Simon Josefsson via Gnulib discussion list
2021-06-11 12:21                     ` Eric Blake
2021-06-11 13:57                       ` Bruno Haible

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

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

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

  git send-email \
    --in-reply-to=7804088.cEBGB3zze1@nimes \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=collin.funk1@gmail.com \
    --cc=eggert@cs.ucla.edu \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).