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: Wed, 27 Oct 2021 20:02:44 +0200

On Wed, 27 Oct 2021 17:36:07 +0000 Greg Chicares <gchicares@sbcglobal.net> 
wrote:

GC> On 10/27/21 12:15 PM, Vadim Zeitlin wrote:
GC> > On Tue, 26 Oct 2021 23:17:46 +0000 Greg Chicares 
<gchicares@sbcglobal.net> wrote:
GC> > 
GC> > GC> I would like to add a test case for '-Wuninitialized-const-reference'
GC> > GC> to 'miscellany_test.cpp'.
GC> > 
GC> >  Sorry, but how exactly would this work? I don't think we have any tests
GC> > checking for failing compilation in lmi
GC> 
GC> Correct. Let me show you something I hope to commit soon
GC> (I've already merged the two template functions and
GC> simplified the name they now share):
GC> 
GC> --8<---8<---8<---8<---8<---8<---8<---8<---8<---8<-
GC>     // Variable neither initialized nor used.
GC>     int a;
GC>     stifle_unused_warning(a);
GC> 
GC>     // Variable initialized but not used.
GC>     int b {2};
GC>     stifle_unused_warning(b);
GC> 
GC>     // Variable initialized and used, but only conditionally.
GC>     int c;
GC> #if defined some_undefined_condition
GC>     c = 3;
GC>     std::cout << c << " This should not print" << std::endl;
GC> #endif // defined some_undefined_condition
GC>     stifle_unused_warning(c);
GC> 
GC>     // Variable initialized and later used...
GC>     int volatile d {4};
GC>     stifle_unused_warning(d);
GC>     // ...but last value not used.
GC>     for(int i = 0; i < 7; ++i)
GC>         {
GC>         d = static_cast<int>(std::clock());
GC>         }
GC>     stifle_unused_warning(d);
GC> -<8---<8---<8---<8---<8---<8---<8---<8---<8---<8--
GC> 
GC> Running these unit tests only verifies that stifle_unused_warning()
GC> prevents compiler warnings. Their real purpose is documentary: they
GC> demonstrate several different intended use cases.

 I see, thanks.

GC> For {a,b,c}, those tests are straightforward. If I comment out
GC> the stifle_unused_warning() calls, then gcc gives warnings;
GC> with those calls left in place, it gives none.

 The question is whether it would be worth running the compiler with
"-Dstifle_unused_warning(x)=''" on the command line and checking that it
fails with the expected warning?

GC> For 'd', though, I'm trying to write tests to cover the sort
GC> of problem discussed here:
GC>   https://lists.nongnu.org/archive/html/lmi/2021-04/msg00058.html
GC> which clang complained about but gcc didn't. I should probably
GC> just install clang and figure out how to use it,

 Using it is pretty straightforward, as it's just another Unix compiler,
i.e. all the standard options are the same as for gcc. It almost certainly
doesn't work with the lmi makefiles as they explicitly check for gcc
version, but this shouldn't be difficult to fix. Or, of course, you could
always just do

        $ mkdir -p build/clang
        $ ./autogen.sh
        $ cd $_
        $ ../../configure CC=clang-12 CXX='clang++-12 -stdlib=libc++'
        $ make

which works out of the box.

 Regards,
VZ

Attachment: pgpdIaDZi4lJD.pgp
Description: PGP signature


reply via email to

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