Skip to content

support C++20 standard#26590

Merged
asmorkalov merged 12 commits intoopencv:4.xfrom
Kumataro:fix26589
Dec 17, 2024
Merged

support C++20 standard#26590
asmorkalov merged 12 commits intoopencv:4.xfrom
Kumataro:fix26589

Conversation

@Kumataro
Copy link
Copy Markdown
Contributor

@Kumataro Kumataro commented Dec 7, 2024

Close #26589
Related opencv/opencv_contrib#3842
Related: #20269

  • do not arithmetic enums and ( different enums or floating numeric)
  • remove unused variable

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

- use constexpr instead of enum definition value
- cast to calicurate mixing different enums
- do not increment volatile variable
- remove unused variable
- use vector.reserve() instead of vector.resise() after vector.clear()
@asmorkalov
Copy link
Copy Markdown
Contributor

@Kumataro Thanks a lot for the contribution! Please take a look on #26284.

@Kumataro
Copy link
Copy Markdown
Contributor Author

Kumataro commented Dec 9, 2024

Thank you for your comment ! I fixed with ”+ENUM” method for enum arithmetic.

There are some enum definitions to define const numerics.
I think it is better to replace to ‘constexpr' for C++11 and upper to optimize.

@Kumataro
Copy link
Copy Markdown
Contributor Author

I'm sorry, I append to fix boost.cpp to remove static_cast<>.

hashtab.clear();
hashtab.resize(HASH_SIZE0);
pool.clear();
pool.resize(nodeSize);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not safe replacement. Pool elements cannot be used after it, but they could be before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your point, GCC 13 + C++20 shows warning, so I append pragma to suppress it.

Copy link
Copy Markdown
Contributor

@VadimLevin VadimLevin left a comment

Choose a reason for hiding this comment

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

From my perspective using + trick for suppressing enum arithmetic is way too obscure.
Why not to use static_cast<*> where it is required? It describes clearly describes intent.

@Kumataro
Copy link
Copy Markdown
Contributor Author

I limited to use +enum trick for only combination difference enums. For arithmetic between enums and float/double. static_cast<>(enum) is used.

@asmorkalov
Copy link
Copy Markdown
Contributor

@Kumataro Thanks a lot for the contribution! We have some issues with x86 linux host in CI. I'll merge the patch as soon as we fix the configuration.

@asmorkalov asmorkalov self-assigned this Dec 16, 2024
@asmorkalov asmorkalov added this to the 4.11.0 milestone Dec 17, 2024
@asmorkalov asmorkalov merged commit 260f511 into opencv:4.x Dec 17, 2024
@asmorkalov asmorkalov mentioned this pull request Jan 15, 2025
shyama7004 pushed a commit to shyama7004/opencv that referenced this pull request Jan 20, 2025
Support C++20 standard opencv#26590

Close opencv#26589
Related opencv/opencv_contrib#3842
Related: opencv#20269

- do not arithmetic enums and ( different enums or floating numeric) 
- remove unused variable

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
NanQin555 pushed a commit to NanQin555/opencv that referenced this pull request Feb 24, 2025
Support C++20 standard opencv#26590

Close opencv#26589
Related opencv/opencv_contrib#3842
Related: opencv#20269

- do not arithmetic enums and ( different enums or floating numeric) 
- remove unused variable

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support C++20 standard for GCC and clang

4 participants