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

Polymorphic type reference error during build #3574

Closed
3 of 4 tasks
aktiver opened this issue Oct 10, 2023 · 0 comments · Fixed by #3584
Closed
3 of 4 tasks

Polymorphic type reference error during build #3574

aktiver opened this issue Oct 10, 2023 · 0 comments · Fixed by #3584

Comments

@aktiver
Copy link

aktiver commented Oct 10, 2023

System Information

This error occurs after make j*:


Scanning dependencies of target opencv_perf_imgproc
[ 37%] Building CXX object modules/imgproc/CMakeFiles/opencv_perf_imgproc.dir/perf/opencl/perf_3vs4.cpp.o
[ 37%] Building CXX object modules/cudaarithm/CMakeFiles/opencv_test_cudaarithm.dir/test/test_event.cpp.o
[ 37%] Building CXX object modules/cudaarithm/CMakeFiles/opencv_perf_cudaarithm.dir/perf/perf_element_operations.cpp.o
/home/ubuntu/opencv_contrib/modules/cudaarithm/test/test_event.cpp: In member function ‘void opencv_test::{anonymous}::AsyncEvent_Timing_Test::UnsafeTestBody()’:
/home/ubuntu/opencv_contrib/modules/cudaarithm/test/test_event.cpp:94:30: warning: catching polymorphic type ‘class cv::Exception’ by value [-Wcatch-value=]
   94 |         catch (cv::Exception ex) {


The warning message you're seeing is related to catching a polymorphic type by value instead of by reference. In C++, it's a good practice to catch exceptions by reference rather than by value to preserve the exception type information and to avoid object slicing.

Here's how you could fix this warning:

Change this line:
catch (cv::Exception ex) {

To:
catch (const cv::Exception& ex) {

Detailed description

By making this change, you're catching the exception by reference, which should eliminate the warning message. Now go back to your source code, find the file test_event.cpp, locate line 94, and make the suggested change. Save the file and re-compile your project. This should resolve the warning you were seeing.

Steps to reproduce

make j*

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
@aktiver aktiver added the bug label Oct 10, 2023
@mshabunin mshabunin transferred this issue from opencv/opencv Oct 10, 2023
@asmorkalov asmorkalov self-assigned this Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants