lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Stifling "unused" warnings


From: Vadim Zeitlin
Subject: Re: [lmi] Stifling "unused" warnings
Date: Thu, 28 Oct 2021 01:51:18 +0200

On Wed, 27 Oct 2021 22:33:32 +0000 Greg Chicares <gchicares@sbcglobal.net> 
wrote:

GC> On 10/27/21 6:02 PM, Vadim Zeitlin wrote:
GC> [...]
GC> > GC> For {a,b,c}, those tests are straightforward. If I comment out
GC> > GC> the stifle_unused_warning() calls, then gcc gives warnings;
GC> > GC> with those calls left in place, it gives none.
GC> > 
GC> >  The question is whether it would be worth running the compiler with
GC> > "-Dstifle_unused_warning(x)=''" on the command line and checking that it
GC> > fails with the expected warning?
GC> 
GC> Since commit bc7259fb, the question is whether clang
GC> gives zero warnings with origin/master, but gives
GC> exactly the two warnings expected with the patch below.

 clang-12 gives only one of the expected warnings:

miscellany_test.cpp:470:9: error: private field 'unused_' is not used 
[-Werror,-Wunused-private-field]
    int unused_;
        ^

I don't fully understand what's going on here, but I just can't get any
-Wunused-variable for "d" with clang 12 unless I remove the assignment to
it inside the loop, even removing volatile doesn't help. I.e. somehow
initializing a variable and not using it provokes this warning, but
initializing a variable and then assigning to it suppresses it.

 FWIW gcc 11 does give a warning with this patch

miscellany_test.cpp: In function ‘void test_stifle_unused_warning()’:
miscellany_test.cpp:492:18: error: variable ‘d’ set but not used 
[-Werror=unused-but-set-variable]
  492 |     int volatile d {4};
      |                  ^


 The real problem, however, is that it also gives a warning without this
patch, resulting in a new CI build failure:

miscellany_test.cpp: In function ‘void test_stifle_unused_warning()’:
miscellany_test.cpp:477:26: error: ‘a’ may be used uninitialized 
[-Werror=maybe-uninitialized]
  477 |     stifle_unused_warning(a);
      |     ~~~~~~~~~~~~~~~~~~~~~^~~
In file included from miscellany_test.cpp:24:
miscellany.hpp:296:16: note: by argument 1 of type ‘const int&’ to ‘constexpr 
void stifle_unused_warning(const T&) [with T = int]’ declared here
  296 | constexpr void stifle_unused_warning(T const&)
      |                ^~~~~~~~~~~~~~~~~~~~~
miscellany_test.cpp:476:9: note: ‘a’ declared here
  476 |     int a;
      |         ^

 So we now have the same problem as we used to have for clang (but somehow
don't any more) for gcc 11. Removing the const from the function signature
does fix it, please see my stifle-unused-non-const branch on GitHub which
passed CI, but I wonder if we shouldn't actually take a "T&&" here to allow
passing r-value references too, to allow using things like

        stifle_unused_warning(a + b);

for example, what do you think?

VZ

Attachment: pgpRdLw1cnj0q.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]