no warning when assigning a string to itself; infinite loop when printing a string
Jonathan Wakely
jwakely.gcc@gmail.com
Mon May 23 02:06:00 GMT 2011
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.
More information about the Gcc-help
mailing list