This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: no warning when assigning a string to itself; infinite loop when printing a string


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]