ddavis2speedray / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Unused variable warning when building with clang #321

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When building chromium in release mode with clang, clang complains about the 
unused variable |last| in this function from gtest-linked_ptr.h:

  T* release() {
    bool last = link_.depart();
    assert(last);
    T* v = value_;
    value_ = NULL;
    return v;
  }

We build chromium with -Werror, and this file ends up being included  in our 
test source files. This causes over 1000 compile errors in the chromium code 
and prevents a release build.

A possible fix is to add

  (void)last;  // To silence an "unused variable" warning.

after the assert line.

Original issue reported on code.google.com by thakis@google.com on 10 Oct 2010 at 10:35

GoogleCodeExporter commented 9 years ago
Patch, fwiw:

Index: include/gtest/internal/gtest-linked_ptr.h
===================================================================
--- include/gtest/internal/gtest-linked_ptr.h   (revision 435)
+++ include/gtest/internal/gtest-linked_ptr.h   (working copy)
@@ -177,6 +177,7 @@
   T* release() {
     bool last = link_.depart();
     assert(last);
+    (void)last;
     T* v = value_;
     value_ = NULL;
     return v;

Original comment by thakis@google.com on 10 Oct 2010 at 10:56

GoogleCodeExporter commented 9 years ago
Thanks for the patch.  It looks good.

While we test gtest rigorously, there's no guarantee that you'll be using the 
same compiler, or the same version of the compiler, and the same compiler flags 
as we do.  Therefore you may see other warnings coming up in the future.

If you use -Werror with gtest, I suggest that you use the -isystem flag to mark 
gtest headers as system headers.  That'll suppress warnings from gtest headers. 
 This is what Kenton Varda suggests users of protobuf do too.

Original comment by w...@google.com on 11 Oct 2010 at 5:15

GoogleCodeExporter commented 9 years ago
Thanks, that's a good suggestion.

Original comment by thakis@google.com on 11 Oct 2010 at 5:22

GoogleCodeExporter commented 9 years ago
Fixed in r492.

Original comment by w...@google.com on 11 Oct 2010 at 6:30