On 11/8/2013 7:31 PM, Tom Browder wrote:
I am trying to use Boost 1.54.0 to replace a previous version (1.47) and am using g++ 4.7 with most warnings turned on. I am getting many -Wshadow errors and wonder why they exist. Surely the developers test for such.
Here is one example from xpressive/detail/utility/hash_peek_bitset.hpp:
Both 'icase' and 'count' are reported to shadow members of 'this'.
Note that the bool arg is named 'icase' but the compiler reports 'this' has a member named 'icase' (as can be plainly seen below). In this example it's fairly clear what is intended, but then again maybe not (and it doesn't give the user much confidence in the code). It isn't good practice IMHO to do such so that is why I like to use some prefix or suffix to disambiguate the two variables.
// Make sure all sub-expressions being merged have the same case-sensitivity bool test_icase_(bool icase) { std::size_t count = this->bset_.count();
if(256 == count) { return false; // all set already, nothing to do } else if(0 != count && this->icase_ != icase) { this->set_all(); // icase mismatch! set all and bail return false; }
this->icase_ = icase; return true; }
I could file many bugs but it begs the question of why the warnings are allowed in the first place.
Maybe I don't see all of the context but how does icase shadow icase_ in the code above? Also std::size_t count = this->bset_.count(); seems perfectly fine to me - less of an issue than picking a less suitable variable name. Jeff