Opened 7 years ago

Closed 6 years ago

#11740 closed Bugs (fixed)

string_ref not working correctly with rvalue of std::string

Reported by: steweg@… Owned by: No-Maintainer
Milestone: Component: utility
Version: Boost 1.59.0 Severity: Problem
Keywords: string_ref Cc:

Description

This is currently allowed: boost::string_ref something; something = "temp"; works ok something = std::string("temp"); doesn't work corretly

while it should not be a should only be: boost::string_ref something; something = "temp"; works ok std::string tempStr("temp"); something = tempStr; works ok

Current version is pointing to buffer that is no longer part of any std::string, therefore if you use something like valgrind it will trigger and error.

Attached is a simple patch that prevent this.

Attachments (2)

patch (171 bytes ) - added by steweg@… 7 years ago.
proposed patch
decription with formatting.txt (292 bytes ) - added by steweg@… 7 years ago.
Descirption (again) with correct formatting

Download all attachments as: .zip

Change History (3)

by steweg@…, 7 years ago

Attachment: patch added

proposed patch

by steweg@…, 7 years ago

Descirption (again) with correct formatting

comment:1 by Marshall Clow, 6 years ago

Resolution: fixed
Status: newclosed

Fixed w/ a test in 9960d9f395b79ee860e39064cd46961f76d2cb55 Unfortunately, the fix only works in C++11 and later.

Note: See TracTickets for help on using tickets.