Opened 11 years ago

Closed 10 years ago

#6771 closed Bugs (fixed)

unordered_map comparing float in assertion statement causes large warning in gcc

Reported by: Ryan Fogarty <ryan.fogarty.msece@…> Owned by: Daniel James
Milestone: Boost 1.50.0 Component: unordered
Version: Boost Release Branch Severity: Problem
Keywords: Cc:

Description

In unordered/detail/table.hpp an assertion statement in function

std::size_t min_buckets_for_size(std::size_t size) const

compares a floating point which causes deeply nested warning statements in gcc with some compiler flags (possibly -Wall/-Wfloat-equal/-pedantic)

            BOOST_ASSERT(this->mlf_ != 0);

Because of the nature of the template code the warning is very difficult to read and it is not obvious whether it is a problem in user's code or the library (from a quick glance). A simple alternative eliminates the issue:

            BOOST_ASSERT(this->mlf_ > 0.0f || this->mlf_ < 0.0);

Bug has existed for quite a while. It is at least as old as 1.46, and I've confirmed that exists in 1.47 (line:138) - 1.49 (line:387) and is also on the trunk.

As an example The warning in gcc 4.7.0 ends with: /usr/local/boost_1_49_0/include/boost/unordered/detail/table.hpp:387:13: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]

Change History (2)

comment:1 by Daniel James, 11 years ago

(In [77832]) Unordered/hash: Avoid a gcc warning. Refs #6771

comment:2 by Daniel James, 10 years ago

Milestone: To Be DeterminedBoost 1.50.0
Resolution: fixed
Status: newclosed

Merged to release in [78319]

Note: See TracTickets for help on using tickets.