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

Steve MacKenzie stevemac321 at live.com
Fri Oct 17 19:31:33 PDT 2014


Makes sense, updated patch attached.
Thx, Steve

On 10/17/2014 06:45 PM, Eric Fiselier wrote:
> Hi Steve,
>
> It seems most of the changes just remove unused variables after they 
> are initialized. Isn't the initialization part of the test?
> For example, if the return type of `foo()` is specified to be a type 
> that is BooleanConvertible then doesn't it make sense to test `bool 
> unused = foo()`?
> I would rather just see the variables be used as opposed to their 
> ommision. Even if using them just means `((void)unused)`.
>
> /Eric
>
> On Fri, Oct 17, 2014 at 7:24 PM, Steve MacKenzie <stevemac321 at live.com 
> <mailto:stevemac321 at live.com>> wrote:
>
>     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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141017/c6a6e517/attachment.html>
-------------- 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)
@@ -68,6 +68,7 @@
         std::atomic_init(&obj, true);
         assert(obj == true);
         bool b0 = obj.is_lock_free();
+        (void)b0; // to placate scan-build
         obj.store(false);
         assert(obj == false);
         obj.store(true, std::memory_order_release);
@@ -123,6 +124,7 @@
         std::atomic_init(&obj, true);
         assert(obj == true);
         bool b0 = obj.is_lock_free();
+        (void)b0; // to placate scan-build
         obj.store(false);
         assert(obj == false);
         obj.store(true, std::memory_order_release);
@@ -178,6 +180,7 @@
         std::atomic_init(&obj, true);
         assert(obj == true);
         bool b0 = obj.is_lock_free();
+        (void)b0; // to placate scan-build
         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)
@@ -55,6 +55,7 @@
         assert(next(m.begin(), 5)->second == 2);
 
         i = m.erase(2);
+        (void)i; // to placate scan-build
         assert(m.size() == 6);
         assert(i == 0);
         assert(next(m.begin(), 0)->first == 1);
@@ -71,6 +72,7 @@
         assert(next(m.begin(), 5)->second == 2);
 
         i = m.erase(3);
+        (void)i; // to placate scan-build
         assert(m.size() == 3);
         assert(next(m.begin(), 0)->first == 1);
         assert(next(m.begin(), 0)->second == 1);
@@ -135,6 +137,7 @@
         assert(next(m.begin(), 5)->second == 2);
 
         i = m.erase(3);
+        (void)i; // to placate scan-build
         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)
@@ -30,5 +30,6 @@
         typedef std::array<T, 0> C;
         C c = {};
         T* p = c.data();
+        (void)p; // to placate scan-build
     }
 }
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)
@@ -30,5 +30,6 @@
         typedef std::array<T, 0> C;
         const C c = {};
         const T* p = c.data();
+        (void)p; // to placate scan-build
     }
 }
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)
@@ -19,4 +19,5 @@
 {
     std::complex<double> cd;
     double x = sin(1.0);
+    (void)x; // to placate scan-build
 }
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)
@@ -33,6 +33,7 @@
 
     std::stringstream ss;
     bool skippingws = is_skipws ( &ss );
+    (void)skippingws; // to placate scan-build
     ss << q;
     ss >> q;
     }


More information about the cfe-commits mailing list