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

Fix for C4146 Error in CPUNegElementKernel with Unsigned Types #6534

Merged
merged 2 commits into from
Dec 29, 2023

Conversation

eclipse0922
Copy link
Contributor

@eclipse0922 eclipse0922 commented Dec 13, 2023

Fix the compile error.
UnaryEWCPU.cpp(100): error C4146: unary minus operator applied to unsigned type, result still unsigned

Type

  • Bug fix (non-breaking change which fixes an issue): Fixes #
  • New feature (non-breaking change which adds functionality). Resolves #
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) Resolves #

Motivation and Context

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

The CPUNegElementKernel function in UnaryEWCPU.cpp triggers a compilation error (C4146) when instantiated with an unsigned scalar_t type.
This error is caused by applying the unary minus operator to an unsigned type, where the result remains unsigned, leading to undefined behavior.

I am tyring to write port for vpckg.
I got C4146 error during the compilations.

manual build option( other options are default)

        -DBUILD_SHARED_LIBS=OFF
        -DWITH_OPENMP=OFF
        -DBUILD_EXAMPLES=OFF
        -DBUILD_UNIT_TESTS=OFF
        -DBUILD_BENCHMARKS=OFF
        -DBUILD_GUI=OFF
        -DBUILD_ISPC_MODULE=OFF
        -DUSE_SYSTEM_EIGEN3=ON
        -DUSE_SYSTEM_CURL=ON
        -DUSE_SYSTEM_GLEW=ON
        -DUSE_SYSTEM_GLFW=ON
        -DUSE_SYSTEM_JPEG=ON
        -DUSE_SYSTEM_LIBLZF=OFF
        -DUSE_SYSTEM_PNG=OFF
        -DUSE_SYSTEM_TINYGLTF=ON
        -DUSE_SYSTEM_TINYOBJLOADER=ON
        -DUSE_SYSTEM_FMT=ON
        -DUSE_SYSTEM_PYBIND11=ON
        -DUSE_SYSTEM_GOOGLETEST=ON
        -DUSE_SYSTEM_IMGUI=ON
        -DBUILD_PYTHON_MODULE=OFF
        -DBUILD_LIBREALSENSE=OFF
        -DBUILD_AZURE_KINECT=OFF
        -DBUILD_FILAMENT_FROM_SOURCE=OFF
        -DSTATIC_WINDOWS_RUNTIME=${STATIC_WINDOWS_RUNTIME}
        -DBUILD_CUDA_MODULE=OFF
        -DBUILD_TENSORFLOW_OPS=OFF
        -DGLIBCXX_USE_CXX11_ABI=ON
        -DDEVELOPER_BUILD=OFF

OS: windows 11
Compiler:MSVC (visuals studio 2022 17.8)

UnaryEWCPU.cpp(100): error C4146: unary minus operator applied to unsigned type, result still unsigned
Copy link

update-docs bot commented Dec 13, 2023

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

@ssheorey
Copy link
Member

Hi @eclipse0922 thank you for submitting this PR. Can you check the CI errors, please?

@eclipse0922
Copy link
Contributor Author

@ssheorey Sure!

@ssheorey ssheorey self-requested a review December 26, 2023 16:01
@eclipse0922
Copy link
Contributor Author

FYI,
If c++17 is the baseline, we can use if constexpr, but it does not seem to use c++17 by default.

Copy link
Member

@ssheorey ssheorey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this! Btw, at this point one of the main issues with not switching to C++17 is some build errors with MSVC in Visual Studio 2019. If you are interested, we would welcome a PR switching over to C++17. I think Visual Studio 2022 is now available in GIthub CI if that is required.

@ssheorey ssheorey merged commit 846754b into isl-org:main Dec 29, 2023
36 checks passed
@eclipse0922 eclipse0922 deleted the EWCPU_fix branch December 31, 2023 07:12
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