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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In the attached code, the line "const string str = str;" doesn't give
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")

Also, when trying to print the string, it seems to execute forever.


Thanks,
Steve
/*

$ g++ --version
g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
Copyright (C) 2010 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.

$ g++ -Wall gcc_no_warning.cpp && ./a.out

*/

#include <iostream>

using namespace std;

int main()
{
	// no warning
	const string str = str;

	// infinite loop
	cout << str << endl;

	return 0;
}

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux