Skip to content

Polymorphic type reference error during build #3574

@aktiver

Description

@aktiver

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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions