Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 1451986 Details for
Bug 1591823
c++17 data() member function of std::string undesired side effects
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
c++ file to reproduce the problem
a.cpp (text/x-csrc), 1.55 KB, created by
Hubert Krause
on 2018-06-15 16:12:40 UTC
(
hide
)
Description:
c++ file to reproduce the problem
Filename:
MIME Type:
Creator:
Hubert Krause
Created:
2018-06-15 16:12:40 UTC
Size:
1.55 KB
patch
obsolete
>#include <iostream> >#include <string> > >int main() >{ > const std::string s0{"hello world"}; > std::string s1 {s0}; > std::string s2 {s0}; > std::cout << "BEFORE" << std::endl; > std::cout << "s0 = " << s0 << std::endl; > std::cout << "s1 = " << s1 << std::endl; > std::cout << "s2 = " << s2 << std::endl; > >#if 0 > char* pszDataS1 = &s1[0]; //this old trick works as expected! >#else > char* pszDataS1 = s1.data(); //this new data() member function leads to very serious and undesired side effects! >#endif > *pszDataS1 = ' '; //should modify s1 and only s1, should *never* modify both s2 and the const(!) s0. > > std::cout << "AFTER modifying s1" << std::endl; > std::cout << "s0 = " << s0 << " expecting = hello world" << std::endl; > std::cout << "s1 = " << s1 << " expecting = ello world" << std::endl; > std::cout << "s2 = " << s2 << " expecting = hello world" << std::endl; > > return 0; >} > >//th@vcrhel7-dev-thaase:[~/sandbox]: gcc --version >//gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5) >//Copyright (C) 2017 Free Software Foundation, Inc. >//This is free software; see the source for copying conditions. There is NO >//warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. >// >//th@vcrhel7-dev-thaase:[~/sandbox]: g++ -std=c++17 a.cpp >//th@vcrhel7-dev-thaase:[~/sandbox]: ./a.out >// >//leads to the following console output, showing very serious and undesired side effects on s2 and (const!) s0. >//s0 = hello world! >//s1 = hello world! >//s2 = hello world! >//s0 = ello world! >//s1 = ello world! >//s2 = ello world!
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1591823
: 1451986