Bug #81639 Replace the macro IS_SINGLE_FLAG() with a portable constexpr function
Submitted: 30 May 2016 8:25 Modified: 30 May 2016 13:39
Reporter: Marko Mäkelä Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0.0 OS:Any
Assigned to: CPU Architecture:Any

[30 May 2016 8:25] Marko Mäkelä
Description:
MySQL needs a predicate that can check if there is a single bit set in an integer.

sql/parse_tree_nodes.h already defines the macro IS_SINGLE_FLAG(X), but it is not portable, because it depends on the GCC __builtin_popcount(). That is acceptable for static_assert() but not for more general use.

How to repeat:
See above.

Suggested fix:
In my_bit.h, introduce

template<typename IntType>
constexpr bool is_single_bit(IntType bits)
{
  return bits != 0 && (bits & (bits - 1)) == 0;
}
[30 May 2016 13:39] Paul DuBois
Posted by developer:
 
Fixed in 5.8.0.

Code cleanup. No changelog entry needed.
[18 Jun 2016 21:38] Omer Barnir
Posted by developer:
 
Reported version value updated to reflect release name change from 5.8 to 8.0