Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] Rename __bit_reference template parameter to avoid conflict #80661

Merged
merged 2 commits into from
Feb 5, 2024

Conversation

DimitryAndric
Copy link
Collaborator

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 _Fill_Value to avoid the conflict.

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 `_Fill_Value` to avoid the conflict.
@DimitryAndric DimitryAndric requested a review from a team as a code owner February 5, 2024 10:59
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 5, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 5, 2024

@llvm/pr-subscribers-libcxx

Author: Dimitry Andric (DimitryAndric)

Changes

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 _Fill_Value to avoid the conflict.


Full diff: https://github.com/llvm/llvm-project/pull/80661.diff

1 Files Affected:

  • (modified) libcxx/include/__bit_reference (+5-5)
diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference
index 9032b8f018093..e0b647eb62a8a 100644
--- a/libcxx/include/__bit_reference
+++ b/libcxx/include/__bit_reference
@@ -173,7 +173,7 @@ private:
 
 // fill_n
 
-template <bool _FillValue, class _Cp>
+template <bool _Fill_Value, 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>;
@@ -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 (_Fill_Value)
       *__first.__seg_ |= __m;
     else
       *__first.__seg_ &= ~__m;
@@ -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, _Fill_Value ? 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 (_Fill_Value)
       *__first.__seg_ |= __m;
     else
       *__first.__seg_ &= ~__m;
@@ -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 _Fill_Value, 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>

@philnik777
Copy link
Contributor

Let's rename it to _FillVal instead to keep the style.

@DimitryAndric DimitryAndric merged commit 1ec2522 into main Feb 5, 2024
25 of 26 checks passed
@DimitryAndric DimitryAndric deleted the users/DimitryAndric/libcxx-fillvalue-collision branch February 5, 2024 16:41
@ldionne
Copy link
Member

ldionne commented Feb 5, 2024

@DimitryAndric Please file a bug report against NetCDF. They are using a reserved name.

@DimitryAndric
Copy link
Collaborator Author

I filed Unidata/netcdf-c#2858, but it appears to be a historical mistake which is part of the NetCDF API now.

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Feb 5, 2024
…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.

(cherry picked from commit 1ec2522)
llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Feb 5, 2024
…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.

(cherry picked from commit 1ec2522)
agozillon pushed a commit to agozillon/llvm-project that referenced this pull request Feb 5, 2024
…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.
tstellar pushed a commit to tstellar/llvm-project that referenced this pull request Feb 14, 2024
…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.

(cherry picked from commit 1ec2522)
tstellar pushed a commit to tstellar/llvm-project that referenced this pull request Feb 14, 2024
…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.

(cherry picked from commit 1ec2522)
tstellar pushed a commit to tstellar/llvm-project that referenced this pull request Feb 14, 2024
…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.

(cherry picked from commit 1ec2522)
tstellar pushed a commit to tstellar/llvm-project that referenced this pull request Feb 14, 2024
…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.

(cherry picked from commit 1ec2522)
@pointhex pointhex mentioned this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants