From: JINMEI Tatuya Date: Fri, 6 Jul 2012 18:07:32 +0000 (-0700) Subject: [1883] workaround a build failure with g++ 4.6 using a mutable variable. X-Git-Tag: trac2351_base~117^2~36^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=400da17fc216ce60be368e20dabdca638c81b45d;p=thirdparty%2Fkea.git [1883] workaround a build failure with g++ 4.6 using a mutable variable. see the comment in the diff for the rationale. --- diff --git a/src/lib/dns/python/pydnspp_common.h b/src/lib/dns/python/pydnspp_common.h index 1513dd99c1..3cc69c4ef8 100644 --- a/src/lib/dns/python/pydnspp_common.h +++ b/src/lib/dns/python/pydnspp_common.h @@ -84,17 +84,22 @@ Py_hash_t convertToPyHash(HashvalType val) { BOOST_STATIC_ASSERT(sizeof(HashvalType) <= sizeof(Py_hash_t)); + // Some versions of g++ doesn't ignore the impossible case of if/else + // below (depending on the size of HashvalType) and triggers a false + // warning. + // To work around it we use an intermediate mutable variable. + // See Trac #1883 for details. + size_t hash_val_bits = CHAR_BIT * sizeof(HashvalType); + if (sizeof(HashvalType) < sizeof(Py_hash_t)) { - // The original hash type has small enough. Do trivial conversion. - const Py_hash_t mask = ~(static_cast(-1) << - (CHAR_BIT * sizeof(HashvalType))); + // The original hash type is small enough. Do trivial conversion. + const Py_hash_t mask = ~(static_cast(-1) << hash_val_bits); return (static_cast(val) & mask); } else { // Clear the highest bit of the original hash so the conversion is // safe and avoids -1. - const HashvalType mask = ~(static_cast(1) << - (CHAR_BIT * sizeof(HashvalType) - 1)); - BOOST_STATIC_ASSERT(mask != static_cast(-1)); + HashvalType mask = ~(static_cast(1) << + (hash_val_bits - 1)); return (val & mask); } }