Skip to content

C++20 std::move(ss).str() first copies and then delete the original string instead of moving it #64644

@AMP999

Description

@AMP999

https://godbolt.org/z/44Ke34fGz

std::stringstream ss("a very long string that exceeds the small string optimization buffer length");
const char *p = ss.view().data();
std::string s = std::move(ss).str();
assert(s.data() == p); // shouldn't be a second allocation

In C++20 and later, moving-out-of ss should move the string, not make a fresh copy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions