This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: no warning when assigning a string to itself; infinite loop when printing a string
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Steve Ward <planet36 at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 22 May 2011 19:34:37 +0100
- Subject: Re: no warning when assigning a string to itself; infinite loop when printing a string
- References: <BANLkTi=vVvo_R4-=_gNUSxpeC5FYXvsGtQ@mail.gmail.com>
On 22 May 2011 19:10, Steve Ward wrote:
> In the attached code, the line "const string str = str;" doesn't give
That's not an assignment, it's construction.
> a warning. ?Is this right? ?If I change the data type to an "int", a
> warning is given. ("warning: 'str' is used uninitialized in this
> function")
It's a bug that there's no warning. It fails to warn for any class types:
struct S { };
int main()
{
const S s = s;
}
I think there's an open bug in bugzilla about this, but I can't find
it right now.
> Also, when trying to print the string, it seems to execute forever.
The program's behaviour is undefined, so it could do anything.