Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in inline std::ostream& operator<<(std::ostream& os, const XLCellValue& value) ? #166

Closed
ofenloch opened this issue Aug 9, 2022 · 4 comments
Labels
bug Something isn't working resolved This issue has been resolved.

Comments

@ofenloch
Copy link

ofenloch commented Aug 9, 2022

This test fails

        XLDocument doc;
        doc.create(fileName);

        auto wks = doc.workbook().worksheet("Sheet1");
        wks.cell("A1").value() = "Hello OpenXLSX!";

        std::stringstream sstream2;
        sstream2 << wks.cell("A1").value();
        // This fails:
        REQUIRE(sstream2.str() == "Hello OpenXLSX!");

Is this a bug or am I doing something wrong?

@ofenloch
Copy link
Author

ofenloch commented Aug 9, 2022

However, casting wks.cell("A1").value() to XLValue makes it work

        // This works:
        std::stringstream sstream2;
        sstream2 << (XLCellValue)wks.cell("A1").value();
        REQUIRE(sstream2.str() == "Hello OpenXLSX!");

        // This fails:
        std::stringstream sstream3;
        sstream3 << wks.cell("A1").value();
        REQUIRE(sstream3.str() == "Hello OpenXLSX!");

ofenloch added a commit to ofenloch/OpenXLSX that referenced this issue Aug 9, 2022
ofenloch added a commit to ofenloch/OpenXLSX that referenced this issue Aug 9, 2022
make sure the CSV line does not end with a separator

add reference tp issue troldal#166
@aral-matrix
Copy link
Collaborator

Is this a bug or am I doing something wrong?

Hi @ofenloch - you actually did find a bug: The XLCellValue overload for operator<< with a string stream was using XLCellValue::get with a reference string type (std::string_view), however this XLCellValue was a temporary object and by the time the return value was to be assigned to the string stream, it was invalid.

I have implemented a fix for the operator overload and a workaround for accessing XLCellValue::get<>() with string references in the development-aral branch, patch 4ed9c97.

I apologize for the late fix, I finally got around to work on the backlog of issues. Will close this when I merge the functionality into master.

@aral-matrix aral-matrix added bug Something isn't working testing Functionality has been implemented in development branch and is pending a merge into main ready to close Pull request has been answered or implemented & is pending closure labels Jan 10, 2025
@aral-matrix aral-matrix added resolved This issue has been resolved. and removed testing Functionality has been implemented in development branch and is pending a merge into main ready to close Pull request has been answered or implemented & is pending closure labels Jan 16, 2025
@aral-matrix
Copy link
Collaborator

merged the patch into master today

@ofenloch
Copy link
Author

Thanks for the update, @aral-matrix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved This issue has been resolved.
Projects
None yet
Development

No branches or pull requests

2 participants