This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/67503] New: String cannot be loaded from binary representation
- From: "radventure at yandex dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 08 Sep 2015 16:28:08 +0000
- Subject: [Bug libstdc++/67503] New: String cannot be loaded from binary representation
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67503
Bug ID: 67503
Summary: String cannot be loaded from binary representation
Product: gcc
Version: 5.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: radventure at yandex dot ru
Target Milestone: ---
#include <iostream>
#include <string>
int main() {
unsigned char buff1[sizeof(std::string)], buff2[sizeof(std::string)];
std::string s1("SMAL STRING BUG"), s2;
new (&buff1) std::string(s1);
s2 = *(reinterpret_cast<std::string*>(&buff1));
std::cout << s2 << std::endl;
std::swap(buff1, buff2);
s2 = *(reinterpret_cast<std::string*>(&buff2));
std::cout << s2 << std::endl;
}
After swapping buffers _N_dataplus._M_p pointer points into we buff1 but actual
data stored in small local buffer was coped correctly. If initial string length
will be greater when data will be stored into the heap and everything will be
Ok.