Commits

Anonymous committed d7e8337

Fix gcc 4.3 warnings.

Comments (0)

Files changed (4)

+2009-09-24  scott snyder  <snyder@bnl.gov>
+
+	* Tagging CxxUtils-00-00-34.
+	* CxxUtils/hashtable.h: Fix warnings.
+	* test/hashtable_test.cxx: Fix warnings.
+	* CxxUtils/no_conversion_warning.h: (new)
+
 2009-09-14  scott snyder  <snyder@bnl.gov>
 
 	* Tagging CxxUtils-00-00-33.

CxxUtils/hashtable.h

 	for (; length > 0; --length)
 	  {
 	    result ^= (std::size_t)*first++;
-	    result *= 1099511628211ULL;
+	    result *= static_cast<std::size_t>(1099511628211ULL); // sss
 	  }
 	return result;
       }
   {
     const unsigned long* const last = X/*<0>*/::primes + X/*<0>*/::n_primes; // sss
     const unsigned long* p = std::lower_bound (X/*<0>*/::primes, last, n); // sss
-    m_next_resize = static_cast<std::size_t>(std::ceil(*p * m_max_load_factor));
+    m_next_resize = static_cast<std::size_t>(std::ceil(static_cast<float>(*p) * m_max_load_factor)); // sss
     return *p;
   }
 
   bkt_for_elements(std::size_t n) const
   {
     const unsigned long* const last = X/*<0>*/::primes + X/*<0>*/::n_primes; // sss
-    const float min_bkts = n / m_max_load_factor;
+    const float min_bkts = static_cast<float>(n) / m_max_load_factor; // sss
     const unsigned long* p = std::lower_bound (X/*<0>*/::primes, last, // sss
 					       min_bkts, lt());
-    m_next_resize = static_cast<std::size_t>(std::ceil(*p * m_max_load_factor));
+    m_next_resize = static_cast<std::size_t>(std::ceil(static_cast<float>(*p) * m_max_load_factor)); // sss
     return *p;
   }
 
 	float min_bkts = (float(n_ins) + float(n_elt)) / m_max_load_factor;
 	if (min_bkts > n_bkt)
 	  {
-	    min_bkts = std::max (min_bkts, m_growth_factor * n_bkt);
+	    min_bkts = std::max (min_bkts, m_growth_factor * static_cast<float>(n_bkt)); // sss
 	    const unsigned long* const last = X/*<0>*/::primes + X/*<0>*/::n_primes; // sss
 	    const unsigned long* p = std::lower_bound (X/*<0>*/::primes, last, // sss
 						       min_bkts, lt());
 	    m_next_resize = 
-	      static_cast<std::size_t>(std::ceil(*p * m_max_load_factor));
+	      static_cast<std::size_t>(std::ceil(static_cast<float>(*p) * m_max_load_factor)); // sss
 	    return std::make_pair(true, *p);
 	  }
 	else 
 	  {
 	    m_next_resize = 
-	      static_cast<std::size_t>(std::ceil(n_bkt * m_max_load_factor));
+	      static_cast<std::size_t>(std::ceil(static_cast<float>(n_bkt) * m_max_load_factor));  // sss
 	    return std::make_pair(false, 0);
 	  }
       }

CxxUtils/no_conversion_warning.h

+// $Id$
+/**
+ * @file CxxUtils/no_conversion_warning.h
+ * @author scott snyder <snyder@bnl.gov>
+ * @date Sep, 2009
+ * @brief Disable conversion warnings.
+ *
+ * Include this header first in a compilation unit to disable -Wconversion
+ * warnings.
+ */
+
+
+#if __GNUC__ >= 4
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif

test/hashtable_test.cxx

 {
   bool test __attribute__((unused)) = true;
 
-  for (float lf = 0.1; lf < 101.0; lf *= 10.0)
+  for (float lf = 0.1f; lf < 101.0f; lf *= 10.0f)
     for (int size = 1; size <= 6561; size *= 3)
       {
 	SG::unordered_set<int> us1, us2;
     allocator<pair<const int, char> >, true> m;
  
   for (int i = 0; i < 1000; ++i)
-    m[i] = '0' + i % 9;
+    m[i] = static_cast<char> ('0' + i % 9);
 		
   for (int i = 0; i < 1000; ++i)
     VERIFY( ++m.find(i)->second == '1' + i % 9 );
 {
   bool test __attribute__((unused)) = true;
 
-  for (float lf = 1.0; lf < 101.0; lf *= 10.0)
+  for (float lf = 1.0f; lf < 101.0f; lf *= 10.0f)
     for (int size = 1; size <= 6561; size *= 3)
       {
 	SG::unordered_set<int> us1;
 	  {
 	    const size_type n = size * 81 / i;
 	    us1.rehash(n);
-	    VERIFY( us1.bucket_count() > us1.size() / us1.max_load_factor() );
+	    VERIFY( us1.bucket_count() >
+                    static_cast<float>(us1.size()) / us1.max_load_factor() );
 	    VERIFY( us1.bucket_count() >= n );
 	  }
       }