[PATCH][libcxx] scan-build fixes in tests

Steve MacKenzie stevemac321 at live.com
Fri Oct 17 18:24:39 PDT 2014


I am about half-way through running the libc++ tests with scan-build.  I 
thought it good to submit a patch now for review for feedback rather 
than later.

All the bugs are of the "dead initialization" category. I tried to apply 
the least intrusive fix as possible, which in all but a couple cases, 
involved simply removing the unused lvalue from the statement.  So the 
coverage should remain the same, neither augmented nor diminished.

I did encounter one scan-build false positive, it looks to have been 
reported already (10862). I added a very simple repro to the bug report. 
(I thought about adding a comment in these tests referencing the bug 
10862, but did not, let me know if I should).

The status of the run is being tracked on my blog here:
http://stevemac123.wordpress.com/static-analysis-run/

clang version 3.6.0 (trunk 217475)
Target: x86_64-unknown-linux-gnu
Thread model: posix

Command line used:

can-build -k -V -analyze-headers clang++ -std=c++1y -stdlib=libc++

Thanks,
Steve MacKenzie



-------------- next part --------------
Index: atomics/atomics.types.generic/bool.pass.cpp
===================================================================
--- atomics/atomics.types.generic/bool.pass.cpp	(revision 220047)
+++ atomics/atomics.types.generic/bool.pass.cpp	(working copy)
@@ -67,7 +67,7 @@
         assert(obj == false);
         std::atomic_init(&obj, true);
         assert(obj == true);
-        bool b0 = obj.is_lock_free();
+        obj.is_lock_free();
         obj.store(false);
         assert(obj == false);
         obj.store(true, std::memory_order_release);
@@ -122,7 +122,7 @@
         assert(obj == false);
         std::atomic_init(&obj, true);
         assert(obj == true);
-        bool b0 = obj.is_lock_free();
+        obj.is_lock_free();
         obj.store(false);
         assert(obj == false);
         obj.store(true, std::memory_order_release);
@@ -177,7 +177,7 @@
         assert(obj == false);
         std::atomic_init(&obj, true);
         assert(obj == true);
-        bool b0 = obj.is_lock_free();
+        obj.is_lock_free();
         obj.store(false);
         assert(obj == false);
         obj.store(true, std::memory_order_release);
Index: containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp
===================================================================
--- containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp	(revision 220047)
+++ containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp	(working copy)
@@ -70,7 +70,7 @@
         assert(next(m.begin(), 5)->first == 3);
         assert(next(m.begin(), 5)->second == 2);
 
-        i = m.erase(3);
+        m.erase(3);
         assert(m.size() == 3);
         assert(next(m.begin(), 0)->first == 1);
         assert(next(m.begin(), 0)->second == 1);
@@ -134,7 +134,7 @@
         assert(next(m.begin(), 5)->first == 3);
         assert(next(m.begin(), 5)->second == 2);
 
-        i = m.erase(3);
+        m.erase(3);
         assert(m.size() == 3);
         assert(next(m.begin(), 0)->first == 1);
         assert(next(m.begin(), 0)->second == 1);
Index: containers/sequences/array/array.data/data.pass.cpp
===================================================================
--- containers/sequences/array/array.data/data.pass.cpp	(revision 220047)
+++ containers/sequences/array/array.data/data.pass.cpp	(working copy)
@@ -29,6 +29,6 @@
         typedef double T;
         typedef std::array<T, 0> C;
         C c = {};
-        T* p = c.data();
+        c.data();
     }
 }
Index: containers/sequences/array/array.data/data_const.pass.cpp
===================================================================
--- containers/sequences/array/array.data/data_const.pass.cpp	(revision 220047)
+++ containers/sequences/array/array.data/data_const.pass.cpp	(working copy)
@@ -29,6 +29,6 @@
         typedef double T;
         typedef std::array<T, 0> C;
         const C c = {};
-        const T* p = c.data();
+        c.data();
     }
 }
Index: depr/depr.c.headers/tgmath_h.pass.cpp
===================================================================
--- depr/depr.c.headers/tgmath_h.pass.cpp	(revision 220047)
+++ depr/depr.c.headers/tgmath_h.pass.cpp	(working copy)
@@ -18,5 +18,5 @@
 int main()
 {
     std::complex<double> cd;
-    double x = sin(1.0);
+    sin(1.0);
 }
Index: input.output/iostream.format/quoted.manip/quoted.pass.cpp
===================================================================
--- input.output/iostream.format/quoted.manip/quoted.pass.cpp	(revision 220047)
+++ input.output/iostream.format/quoted.manip/quoted.pass.cpp	(working copy)
@@ -32,7 +32,7 @@
     auto q = std::quoted(str);
 
     std::stringstream ss;
-    bool skippingws = is_skipws ( &ss );
+    is_skipws ( &ss );
     ss << q;
     ss >> q;
     }


More information about the cfe-commits mailing list