Skip to content

Commit

Permalink
[libc++] Rename __bit_reference template parameter to avoid conflict (l…
Browse files Browse the repository at this point in the history
…lvm#80661)

As of 4d20cfc, `__bit_reference`
contains a template `__fill_n` with a bool `_FillValue` parameter.

Unfortunately there is a relatively widely used piece of scientific
software called NetCDF, which exposes a (C) macro `_FillValue` in its
public headers.

When building the NetCDF C++ bindings, this quickly leads to compilation
errors when the macro interferes with the template in `__bit_reference`.

Rename the parameter to `_FillVal` to avoid the conflict.
  • Loading branch information
DimitryAndric authored Feb 5, 2024
1 parent 29d4751 commit 1ec2522
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions libcxx/include/__bit_reference
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private:

// fill_n

template <bool _FillValue, class _Cp>
template <bool _FillVal, class _Cp>
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
__fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
using _It = __bit_iterator<_Cp, false>;
Expand All @@ -185,7 +185,7 @@ __fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
__storage_type __dn = std::min(__clz_f, __n);
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
if (_FillValue)
if (_FillVal)
*__first.__seg_ |= __m;
else
*__first.__seg_ &= ~__m;
Expand All @@ -194,13 +194,13 @@ __fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
}
// do middle whole words
__storage_type __nw = __n / __bits_per_word;
std::fill_n(std::__to_address(__first.__seg_), __nw, _FillValue ? static_cast<__storage_type>(-1) : 0);
std::fill_n(std::__to_address(__first.__seg_), __nw, _FillVal ? static_cast<__storage_type>(-1) : 0);
__n -= __nw * __bits_per_word;
// do last partial word
if (__n > 0) {
__first.__seg_ += __nw;
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
if (_FillValue)
if (_FillVal)
*__first.__seg_ |= __m;
else
*__first.__seg_ &= ~__m;
Expand Down Expand Up @@ -1007,7 +1007,7 @@ private:
friend class __bit_iterator<_Cp, true>;
template <class _Dp>
friend struct __bit_array;
template <bool _FillValue, class _Dp>
template <bool _FillVal, class _Dp>
_LIBCPP_CONSTEXPR_SINCE_CXX20 friend void __fill_n(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);

template <class _Dp, bool _IC>
Expand Down

0 comments on commit 1ec2522

Please sign in to comment.