Skip to content

opencl cv::ocl default class constructors missing noexcept; adds difficulty in later use #19571

@diablodale

Description

@diablodale

Important classes in the cv::ocl namespace like Kernel, Program, Device, etc. are missing the noexcept specifier. This C++11 feature enables easy safe use of such classes when they are default constructed as part of other classes like vector, array, or user-defined classes with member variables. All these classes only set their Impl to zero in their default constructor. I believe adding noexcept is safe and easy. I have a PR ready.

System information (version)

  • OpenCV => 4.5.0+
  • Operating System / Platform => all
  • Compiler => all

Detailed description

class myclass {
  cv::ocl::Program myprogram; // can throw, herefore myclass's default constructor can throw, etc...
  • Currently, noexcept is missing. When classes like myclass above are compiled, the compiler creates default constructors for myclass::myclass() and the compiler-created constructor cascades the lack of noexcept upwards since Program is a member var. This cascade limits programmers choices and flexibility in use of default initialization with containers, ownership, member variables, etc.
  • Declaring them noexcept aligns these classes with ISO C++ guideline F.6 https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f6-if-your-function-may-not-throw-declare-it-noexcept.
  • Will also align with a forthcoming PR to add move-semantics to these classes.
  • Please note, noexcept is a C++11 and newer language feature; therefore this is only for the 4.x and newer branches
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 solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions