Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

mateusztabaka
Copy link
Contributor

libstdc++ that comes with gcc 4.8 doesn't
define getline(basic_istream<char>&&, std::string&)
even if it's part of the c++11 standard.
However we can still use the following:
getline(basic_istream<char>&, std::string&).

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

libstdc++ that comes with gcc 4.8 doesn't
define `getline(basic_istream<char>&&, std::string&)`
even if it's part of the c++11 standard.
However we can still use the following:
`getline(basic_istream<char>&, std::string&)`.
@mateusztabaka
Copy link
Contributor Author

@hzcyf what do you think?

@zihaomu
Copy link
Member

zihaomu commented Jul 28, 2022

Hi @mateusztabaka, thanks for your contribution!

I have a question about the code:
On my local computer (the compiler is llvm13), I found the

std::getline(std::ifstream(video + "/device/interface"), uvcDev.name);

was parsed as the getline(basic_istream<char>&, std::string&) instead of getline(basic_istream<char>&&, std::string&).

@hzcyf
Copy link
Contributor

hzcyf commented Jul 28, 2022

@hzcyf what do you think?

@mateusztabaka Thanks for your test and contribution!

I have tested this PR on ubuntu18.04 with GCC7.5, it‘s running well!
I think your modifications can improve the compatibility of our code. It should be merged.

Sorry for my bad English!

@mateusztabaka
Copy link
Contributor Author

hi @zihaomu. That's interesting, I can see the same behavior that you mentioned with a simple snippet put into compiler explorer: https://gcc.godbolt.org/z/3fcEbaz5M. Also similar behavior I see for gcc >= 6.1. However with no optimizations getline(basic_istream<char>&&, std::string&) is used. Summary in the table below:

compiler/optimizationsgetline version usedlink to CE
clang 13.0.1 with -O3getline(basic_istream&, std::string&)https://gcc.godbolt.org/z/3fcEbaz5M
clang 13.0.1 with -O0getline(basic_istream&&, std::string&)https://gcc.godbolt.org/z/TeMrbohqx
gcc 12.1 with -O3getline(basic_istream&, std::string&)https://gcc.godbolt.org/z/EffabjYbs
gcc 12.1 with -O0getline(basic_istream&&, std::string&)https://gcc.godbolt.org/z/dxxErxhE8
gcc 4.8.5none, compilation errorhttps://gcc.godbolt.org/z/fWYEcGcM5

Copy link
Member

@zihaomu zihaomu left a comment

Choose a reason for hiding this comment

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

LGTM!👍
With this path, it can pass GCC 4.8 successfully.
Passed case: https://gcc.godbolt.org/z/KjbWc156b

@mateusztabaka
Copy link
Contributor Author

Can this be merged or should we wait for someone else's approval (I can see that Alexander Alekhin is on vacation)?

@vpisarev
Copy link
Contributor

vpisarev commented Aug 3, 2022

@alalek, this fixes compile problems on CentOS, which is super-popular in some orgs. Can we merge it quickly?

@asmorkalov asmorkalov self-requested a review August 3, 2022 09:29
@asmorkalov asmorkalov self-assigned this Aug 3, 2022
@opencv-pushbot opencv-pushbot merged commit 8bfe620 into opencv:4.x Aug 3, 2022
@mateusztabaka mateusztabaka deleted the getline branch August 7, 2022 21:58
@alalek alalek mentioned this pull request Aug 21, 2022
@asmorkalov asmorkalov added this to the 4.7.0 milestone Jan 23, 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 this pull request may close these issues.

6 participants