Ticket #6771 (closed Bugs: fixed)

Opened 5 years ago

Last modified 5 years ago

unordered_map comparing float in assertion statement causes large warning in gcc

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


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

comment:1 Changed 5 years ago by danieljames

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

comment:2 Changed 5 years ago by danieljames

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone changed from To Be Determined to Boost 1.50.0

Merged to release in [78319]


Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.