You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by jm...@apache.org on 2019/07/05 19:07:56 UTC

[incubator-datasketches-cpp] 01/01: Fix warnings on both clang and gcc 4.8.5 for unit tests when built with cmake.

This is an automated email from the ASF dual-hosted git repository.

jmalkin pushed a commit to branch clean_warnings
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git

commit 9c6bd280fcbd7c40debdeeb8834373f635f848e2
Author: jmalkin <jm...@users.noreply.github.com>
AuthorDate: Fri Jul 5 12:07:28 2019 -0700

    Fix warnings on both clang and gcc 4.8.5 for unit tests when built with cmake.
---
 cpc/src/u32Table.cpp                   |  4 ++--
 hll/include/HllArray-internal.hpp      |  2 ++
 hll/include/HllSketchImpl-internal.hpp | 14 ++------------
 hll/test/CrossCountingTest.cpp         |  1 +
 hll/test/HllUnionTest.cpp              | 13 +++++++------
 kll/include/kll_sketch.hpp             |  4 +++-
 6 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/cpc/src/u32Table.cpp b/cpc/src/u32Table.cpp
index 217c3fa..8b19d5c 100644
--- a/cpc/src/u32Table.cpp
+++ b/cpc/src/u32Table.cpp
@@ -77,7 +77,7 @@ void u32TableFree (u32Table * self) {
 void u32TableShow (u32Table * self) {
   Long tableSize = 1LL << self->lgSize;
   printf ("\nu32Table (%d valid bits; %lld of %lld slots occupied)\n",
-	  self->validBits, self->numItems, tableSize);
+	  self->validBits, (long long int) self->numItems, (long long int) tableSize);
   //  U32 * arr = self->slots;
   //  Long i;
   //  for (i = 0; i < tableSize; i++) {
@@ -101,7 +101,7 @@ void u32TableClear (u32Table * self) { // clear the table without resizing it
 
 void printU32Array (U32 * array, Long arrayLength) {
   Long i = 0;
-  printf ("\nu32Array [%lld]\n", arrayLength);
+  printf ("\nu32Array [%lld]\n", (long long int) arrayLength);
   for (i = 0; i < arrayLength; i++) {
     printf ("%d:\t%8X\n", (int) i, array[i]);    
   }
diff --git a/hll/include/HllArray-internal.hpp b/hll/include/HllArray-internal.hpp
index d6ea6c9..1dc3e36 100644
--- a/hll/include/HllArray-internal.hpp
+++ b/hll/include/HllArray-internal.hpp
@@ -555,6 +555,8 @@ int HllArray<A>::hllArrBytes(TgtHllType tgtHllType, int lgConfigK) {
     return hll6ArrBytes(lgConfigK);
   case HLL_8:
     return hll8ArrBytes(lgConfigK);
+  default:
+    throw std::invalid_argument("Invalid target HLL type"); 
   }
 }
 
diff --git a/hll/include/HllSketchImpl-internal.hpp b/hll/include/HllSketchImpl-internal.hpp
index eca9af4..485f58f 100644
--- a/hll/include/HllSketchImpl-internal.hpp
+++ b/hll/include/HllSketchImpl-internal.hpp
@@ -25,10 +25,6 @@
 
 namespace datasketches {
 
-#ifdef DEBUG
-static int numImpls = 0;
-#endif
-
 template<typename A>
 HllSketchImpl<A>::HllSketchImpl(const int lgConfigK, const TgtHllType tgtHllType,
                                 const CurMode curMode, const bool startFullSize)
@@ -37,16 +33,10 @@ HllSketchImpl<A>::HllSketchImpl(const int lgConfigK, const TgtHllType tgtHllType
     curMode(curMode),
     startFullSize(startFullSize)
 {
-#ifdef DEBUG
-  std::cerr << "Num impls: " << ++numImpls << "\n";
-#endif
 }
 
 template<typename A>
 HllSketchImpl<A>::~HllSketchImpl() {
-#ifdef DEBUG
-  std::cerr << "Num impls: " << --numImpls << "\n";
-#endif
 }
 
 template<typename A>
@@ -59,7 +49,7 @@ TgtHllType HllSketchImpl<A>::extractTgtHllType(const uint8_t modeByte) {
   case 2:
     return TgtHllType::HLL_8;
   default:
-    throw std::invalid_argument("Invalid current sketch mode");
+    throw std::invalid_argument("Invalid target HLL type");
   }
 }
 
@@ -100,7 +90,7 @@ uint8_t HllSketchImpl<A>::makeFlagsByte(const bool compact) const {
 //  10     1010      HLL_8,     HLL
 template<typename A>
 uint8_t HllSketchImpl<A>::makeModeByte() const {
-  uint8_t byte;
+  uint8_t byte = 0;
 
   switch (curMode) {
   case LIST:
diff --git a/hll/test/CrossCountingTest.cpp b/hll/test/CrossCountingTest.cpp
index 046c231..bf11682 100644
--- a/hll/test/CrossCountingTest.cpp
+++ b/hll/test/CrossCountingTest.cpp
@@ -54,6 +54,7 @@ class CrossCountingTest : public CppUnit::TestFixture {
       checksum += itr->getPair();
       key = itr->getKey(); // dummy
     }
+    CPPUNIT_ASSERT(key >= 0); // avoids "set but unused" warning
     return checksum;
   }
 
diff --git a/hll/test/HllUnionTest.cpp b/hll/test/HllUnionTest.cpp
index f1faeef..8aba01d 100644
--- a/hll/test/HllUnionTest.cpp
+++ b/hll/test/HllUnionTest.cpp
@@ -63,11 +63,11 @@ class HllUnionTest : public CppUnit::TestFixture {
     TgtHllType type2 = HLL_8;
     TgtHllType resultType = HLL_8;
 
-    int lgK1 = 7;
-    int lgK2 = 7;
-    int lgMaxK = 7;
-    int n1 = 7;
-    int n2 = 7;
+    uint64_t lgK1 = 7;
+    uint64_t lgK2 = 7;
+    uint64_t lgMaxK = 7;
+    uint64_t n1 = 7;
+    uint64_t n2 = 7;
     basicUnion(n1, n2, lgK1, lgK2, lgMaxK, type1, type2, resultType);
     n1 = 8;
     n2 = 7;
@@ -147,7 +147,8 @@ class HllUnionTest : public CppUnit::TestFixture {
     }
   }
 
-  void basicUnion(int n1, int n2, int lgk1, int lgk2, int lgMaxK,
+  void basicUnion(uint64_t n1, uint64_t n2,
+		  uint64_t lgk1, uint64_t lgk2, uint64_t lgMaxK,
                   TgtHllType type1, TgtHllType type2, TgtHllType resultType) {
     uint64_t v = 0;
     //int tot = n1 + n2;
diff --git a/kll/include/kll_sketch.hpp b/kll/include/kll_sketch.hpp
index df79a8f..9d65b82 100644
--- a/kll/include/kll_sketch.hpp
+++ b/kll/include/kll_sketch.hpp
@@ -1048,7 +1048,9 @@ void kll_sketch<T, C, S, A>::populate_work_arrays(const kll_sketch& other, T* wo
 template<typename T, typename C, typename S, typename A>
 void kll_sketch<T, C, S, A>::assert_correct_total_weight() const {
   const uint64_t total(kll_helper::sum_the_sample_weights(num_levels_, levels_));
-  assert (total == n_);
+  if (total != n_) {
+    throw std::logic_error("Total weight does not match N");
+  }
 }
 
 template<typename T, typename C, typename S, typename A>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org