fix opencv/opencv#20544 nodiscard for msvc/gcc#20622
fix opencv/opencv#20544 nodiscard for msvc/gcc#20622opencv-pushbot merged 1 commit intoopencv:3.4from diablodale:fix20544-nodiscard
Conversation
alalek
left a comment
There was a problem hiding this comment.
need to do the work with a 4.x specific commit after you up-merge.
I believe separate additional commit after "merge 3.4" should be better.
| * encourages the compiler to issue a warning if the return value is discarded * | ||
| \****************************************************************************************/ | ||
| #ifndef CV_NODISCARD_STD | ||
| # if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) |
There was a problem hiding this comment.
__has_cpp_attribute(nodiscard) should be checked separately (through own #if statement)
There was a problem hiding this comment.
I disagree. The preprocessor follows strict C logic short-circuiting. Therefore if it doesnt support the _has_cpp_attribute quasi-macro, then the part after the && doesn't run.
In addition it is important that both are true. Otherwise I have to write duplicated code so that I correct handle the case of a compiler supporting _has_cpp_attribute but does not support the nodiscard attribute...in that case, it needs to continue on to the other #elif clauses and not exit the entire if chain.
What is your thinking to separate them?
There was a problem hiding this comment.
There are several failed build configurations on CI.
There was a problem hiding this comment.
Thanks for repro. I can fix that. LLVM had a similar problem https://reviews.llvm.org/D57848
These outdated compilers with OSs past end-of-life are troublesome. ✂☠⏲
I'll check the CI results when the CI system is out of maintenance. I checked the PR on the 5 OSs that I listed. Ubuntu 14 w/ gcc 4.x is two years beyond end-of-life so I did not check with it.
There was a problem hiding this comment.
Build logs from CI should be available now.
|
Still no repro I can find that shows the old gcc-only I do not recommend we investigate too much further into the gcc-only method. It is limited both in platforms and in features. Instead, to focus on the standard No repromat.hpp has the old macro on the declaration In void flip( InputArray _src, OutputArray _dst, int flip_mode )
{
CV_INSTRUMENT_REGION();
// this should issue compiler warning
Mat cataMat(10, 10, CV_8UC1);
cataMat.clone();
CV_Assert( _src.dims() <= 2 );
...Ubuntu 14 with gcc 4.8.4 Ubuntu 16 with gcc 5.4.0 Debian stretch with gcc 6.3.0 Ubuntu 18 with gcc 7.5.0 |
|
Also, where/how in It is off by default, yet very important for correct use of attributes [[]] with MSVC. Any new code added to OpenCV is an opportunity for attributes. Yet, if the attribute is places in a syntatically wrong location, MSVC silently ignores it. For example, while coding/testing this PR I was putting the attribute after |
|
Here (under MSVC section after OPENCV_EXTRA_ flags): https://github.com/opencv/opencv/blob/4.5.3/cmake/OpenCVCompilerOptions.cmake#L386 |
- includes workaround for preprocessor non-compliance - enable attribute syntax checking in msvc
fix #20544 with nodiscard for msvc/gcc and applying it to the most common static factories in the api.
PR is set on branch 3.4. Should be able to apply also on 4.x with some minor work.
⚠ 4.x might have additional static factories which need this improved
CV_NODISCARD_STD.I need to know if you will do the additonal work in the up-merge.
Or if I need to do the work with a 4.x specific commit after you up-merge.
Please tell me. 😀
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request