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 14:15:40 +0200

On Tue, 26 Oct 2021 23:17:46 +0000 Greg Chicares <gchicares@sbcglobal.net> 
wrote:

GC> I would like to add a test case for '-Wuninitialized-const-reference'
GC> to 'miscellany_test.cpp'.

 Sorry, but how exactly would this work? I don't think we have any tests
checking for failing compilation in lmi (even though it could be nice to
have them, e.g. I added them to wx some time ago, but this used some dirty
hacks at makefile level)?

GC> But what should that test be? Something like:
GC> 
GC>   int foobar(const int& i) {}
GC>   int i;
GC>   foobar(i);
GC> 
GC> which I copied from
GC>   https://tobias.hieta.se/llvm11-release
GC> ?

 FWIW this does not result in the expected warning but does result in

---------------------------------- >8 --------------------------------------
miscellany_test.cpp:452:23: error: unused parameter 'i' 
[-Werror,-Wunused-parameter]
int foobar(const int& i) {}
                      ^
miscellany_test.cpp:452:27: error: non-void function does not return a value 
[-Werror,-Wreturn-type]
int foobar(const int& i) {}
                          ^
2 errors generated.
---------------------------------- >8 --------------------------------------

 Somewhat to my surprise, fixing this, i.e. using

        void foobar(const int&) {}

still doesn't result in a warning, apparently because clang sees that the
reference is not actually used with such trivial inline function -- even at
-O0. However this:

---------------------------------- >8 --------------------------------------
diff --git a/miscellany_test.cpp b/miscellany_test.cpp
index 9a0506fcc..8712615f3 100644
--- a/miscellany_test.cpp
+++ b/miscellany_test.cpp
@@ -449,8 +449,13 @@ void test_scoped_ios_format()
     LMI_TEST_EQUAL(oss.str(), s);
 }

+void foobar(const int&);
+
 int test_main(int, char*[])
 {
+    int i;
+    foobar(i);
+
     test_each_equal();
     test_files_are_identical();
     test_sup_inf();
---------------------------------- >8 --------------------------------------

does result in

---------------------------------- >8 --------------------------------------
miscellany_test.cpp:457:12: error: variable 'i' is uninitialized when passed as 
a const reference argument here [-Werror,-Wuninitialized-const-reference]
    foobar(i);
           ^
1 error generated.
---------------------------------- >8 --------------------------------------

 Please let me know if you'd like me to test anything more.

 BTW, clang-13 packages have appeared in Debian experimental, I'll try to
test lmi with them too a bit later.

 Regards,
VZ

Attachment: pgpal2F7EQKrw.pgp
Description: PGP signature


reply via email to

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