Skip to content

G-API: Use object instead of reference in extended lifetime case#14946

Merged
alalek merged 2 commits intoopencv:masterfrom
andrey-golubev:obj_not_ref
Jul 2, 2019
Merged

G-API: Use object instead of reference in extended lifetime case#14946
alalek merged 2 commits intoopencv:masterfrom
andrey-golubev:obj_not_ref

Conversation

@andrey-golubev
Copy link
Copy Markdown
Member

This pullrequest changes

const lvalue reference to object since in the given expression a new object is returned from a function.

Original code is a valid behavior since this is the case for extended lifetime of the temporary object (const lvalue reference of the same type is bound to that temporary).

Anyway, the code is doubtful and requires the developer to check for the return type and provide some rationale to ensure the code is correct. Taking this into account, it's easier to replace reference with an object.


References: Temporary Object Lifetime - look at the exceptions from the rules

@andrey-golubev
Copy link
Copy Markdown
Member Author

@dmatveev please review

@dmatveev
Copy link
Copy Markdown
Contributor

dmatveev commented Jul 2, 2019

It still could be (and must be) const.

const is a great hint that the value is never modified in the function and you don't need to track where it may be written to once it is defined as const.

@andrey-golubev
Copy link
Copy Markdown
Member Author

@dmatveev totally makes sense to add const, updated

Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

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

👍 thanks!

@andrey-golubev
Copy link
Copy Markdown
Member Author

@alalek please merge!

@alalek alalek merged commit 2bf8793 into opencv:master Jul 2, 2019
AhiyaHiya added a commit to AhiyaHiya/opencv that referenced this pull request Jul 7, 2019
* master: (74 commits)
  Merge pull request opencv#14917 from rgarnov:gapi_planar_kernels
  Fixed initUndistortRectifyMap AVX2 implementation
  Merge pull request opencv#14959 from dvd42:onnx_clip
  videoio: eliminate build warnings (clang)
  ts: runtime check for misused 'optional' test data files
  3rdparty(itt): support AARCH64
  tensroflow support maxpoolgrad
  Fix blob detector insertion sort
  Fix crash, add assert and test
  Merge pull request opencv#14946 from andrey-golubev:obj_not_ref
  re-enable CPU_BASELINE=FP16 on Armv7 platform
  Merge pull request opencv#14828 from armenpoghosov:parmen_RANSACPointSetRegistrator_getSubset_disaster_cleanup
  Merge pull request opencv#14916 from terfendail:wsignmask_deprecated
  core: evaluate CV_Error() parameters during static scans
  dnn: fix build with Vulkan
  Merge pull request opencv#14936 from StefanBruens:crosscorr_cleanup
  Explicitly default operator= for Vec<T, n>
  Fix JS sample of dnn
  3rdparty: TBB version 2018u1 => 2019u8
  cmake: support rpath-link linker option
  ...
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
G-API: Use object instead of reference in extended lifetime case (opencv#14946)

* Use object instead of reference

* Make the object const
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.

3 participants