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

Commits on Oct 3, 2024

  1. Disambiguate clamp calls in exrToDpx.cpp

    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
    carlocab committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    a92f1bf View commit details
    Browse the repository at this point in the history