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

Disambiguate clamp calls in exrToDpx.cpp #164

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

carlocab
Copy link
Contributor

@carlocab carlocab commented Oct 3, 2024

C++17 now has std::clamp1, so the calls to clamp in this file
cause the compiler to error with2

  /tmp/ctl-20240930-89937-yvomao/CTL-ctl-1.5.3/OpenEXR_CTL/exrdpx/exrToDpx.cpp:172:19: error: call to 'clamp' is ambiguous
    172 |                 (unsigned int) (clamp (float (pixel.r), 0.0f, 1023.0f) + 0.5f);
        |                                 ^~~~~
  /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/c++/v1/__algorithm/clamp.h:35:1: note: candidate function [with _Tp = float]
     35 | clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
        | ^
  /opt/homebrew/include/Imath/ImathFun.h:77:1: note: candidate function [with T = float]
     77 | clamp (T a, T l, T h) IMATH_NOEXCEPT
        | ^
  /tmp/ctl-20240930-89937-yvomao/CTL-ctl-1.5.3/OpenEXR_CTL/exrdpx/exrToDpx.cpp:175:19: error: call to 'clamp' is ambiguous
    175 |                 (unsigned int) (clamp (float (pixel.g), 0.0f, 1023.0f) + 0.5f);
        |                                 ^~~~~
  /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/c++/v1/__algorithm/clamp.h:35:1: note: candidate function [with _Tp = float]
     35 | clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
        | ^
  /opt/homebrew/include/Imath/ImathFun.h:77:1: note: candidate function [with T = float]
     77 | clamp (T a, T l, T h) IMATH_NOEXCEPT
        | ^
  /tmp/ctl-20240930-89937-yvomao/CTL-ctl-1.5.3/OpenEXR_CTL/exrdpx/exrToDpx.cpp:178:19: error: call to 'clamp' is ambiguous
    178 |                 (unsigned int) (clamp (float (pixel.b), 0.0f, 1023.0f) + 0.5f);
        |                                 ^~~~~
  /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/c++/v1/__algorithm/clamp.h:35:1: note: candidate function [with _Tp = float]
     35 | clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
        | ^
  /opt/homebrew/include/Imath/ImathFun.h:77:1: note: candidate function [with T = float]
     77 | clamp (T a, T l, T h) IMATH_NOEXCEPT
        | ^
  3 errors generated.
  make[2]: *** [OpenEXR_CTL/exrdpx/CMakeFiles/exrdpx.dir/exrToDpx.cpp.o] Error 1

Both this code and Imath::clamp long predate std::clamp, so it seems
to me that Imath::clamp is what's intended here.

This fixes a build failure at Homebrew while rebuilding CTL for OpenEXR
3.3.0.3

Footnotes

  1. https://en.cppreference.com/w/cpp/algorithm/clamp

  2. Logs available at https://github.com/Homebrew/homebrew-core/actions/runs/11113893071/job/30879442929?pr=192399#step:3:375

  3. See https://github.com/Homebrew/homebrew-core/pull/192399

C++17 now has `std::clamp`[^1], so the calls to `clamp` in this file
cause the compiler to error with[^2]

      /tmp/ctl-20240930-89937-yvomao/CTL-ctl-1.5.3/OpenEXR_CTL/exrdpx/exrToDpx.cpp:172:19: error: call to 'clamp' is ambiguous
        172 |                 (unsigned int) (clamp (float (pixel.r), 0.0f, 1023.0f) + 0.5f);
            |                                 ^~~~~
      /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/c++/v1/__algorithm/clamp.h:35:1: note: candidate function [with _Tp = float]
         35 | clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
            | ^
      /opt/homebrew/include/Imath/ImathFun.h:77:1: note: candidate function [with T = float]
         77 | clamp (T a, T l, T h) IMATH_NOEXCEPT
            | ^
      /tmp/ctl-20240930-89937-yvomao/CTL-ctl-1.5.3/OpenEXR_CTL/exrdpx/exrToDpx.cpp:175:19: error: call to 'clamp' is ambiguous
        175 |                 (unsigned int) (clamp (float (pixel.g), 0.0f, 1023.0f) + 0.5f);
            |                                 ^~~~~
      /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/c++/v1/__algorithm/clamp.h:35:1: note: candidate function [with _Tp = float]
         35 | clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
            | ^
      /opt/homebrew/include/Imath/ImathFun.h:77:1: note: candidate function [with T = float]
         77 | clamp (T a, T l, T h) IMATH_NOEXCEPT
            | ^
      /tmp/ctl-20240930-89937-yvomao/CTL-ctl-1.5.3/OpenEXR_CTL/exrdpx/exrToDpx.cpp:178:19: error: call to 'clamp' is ambiguous
        178 |                 (unsigned int) (clamp (float (pixel.b), 0.0f, 1023.0f) + 0.5f);
            |                                 ^~~~~
      /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/c++/v1/__algorithm/clamp.h:35:1: note: candidate function [with _Tp = float]
         35 | clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
            | ^
      /opt/homebrew/include/Imath/ImathFun.h:77:1: note: candidate function [with T = float]
         77 | clamp (T a, T l, T h) IMATH_NOEXCEPT
            | ^
      3 errors generated.
      make[2]: *** [OpenEXR_CTL/exrdpx/CMakeFiles/exrdpx.dir/exrToDpx.cpp.o] Error 1

Both this code and `Imath::clamp` long predate `std::clamp`, so it seems
to me that `Imath::clamp` is what's intended here.

This fixes a build failure at Homebrew while rebuilding CTL for OpenEXR
3.3.0.[^3]

[^1]: https://en.cppreference.com/w/cpp/algorithm/clamp
[^2]: Logs available at https://github.com/Homebrew/homebrew-core/actions/runs/11113893071/job/30879442929?pr=192399#step:3:375
[^3]: See Homebrew/homebrew-core#192399
@michaeldsmith
Copy link
Collaborator

thanks for the contribution!

@michaeldsmith michaeldsmith merged commit 8108715 into ampas:master Oct 3, 2024
63 checks passed
@carlocab carlocab deleted the disambiguate-clamp branch October 3, 2024 05:29
@carlocab
Copy link
Contributor Author

carlocab commented Oct 3, 2024

Thanks for the quick review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants