This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/25735] New: Assignment operator broken with multidimensional array strings.
- From: "dtrebilco at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 Jan 2006 12:16:21 -0000
- Subject: [Bug c++/25735] New: Assignment operator broken with multidimensional array strings.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I am not sure if this is correct C++ code anyway, (so please correct me if not)
#include <stdio.h>
#include <string>
using namespace std;
struct TestStruct
{
string testStr[2][2];
/*
TestStruct &operator= (const TestStruct &src)
{
testStr[0][0] = src.testStr[0][0];
testStr[0][1] = src.testStr[0][1];
testStr[1][0] = src.testStr[1][0];
testStr[1][1] = src.testStr[1][1];
return *this;
}
*/
};
int main()
{
TestStruct a, b;
a.testStr[0][0] = "1234567890";
b = a;
printf("Done \n %s", b.testStr[0][0].c_str());
return 0;
}
With no assignment operator, the default generated one causes a "double free or
corruption" error. Single arrays work fine, but I am also unsure what the
correct C++ behaviour should be in this case.
--
Summary: Assignment operator broken with multidimensional array
strings.
Product: gcc
Version: 3.4.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dtrebilco at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25735