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]

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


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]