Bug 17004 - getting warning multiple times
Summary: getting warning multiple times
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.1
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-12 16:01 UTC by Oliver Stoeneberg
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Stoeneberg 2004-08-12 16:01:51 UTC
If I compile this code with "-Wunreachable-code" I get
the warning

C:\Dev-Cpp\Projects\gcc-test\main.cpp
In constructor `CTest::CTest()':
19 C:\Dev-Cpp\Projects\gcc-test\main.cpp
[Warning] will never be executed

twice. If I put the constructor code inline in the class
definition I only get it once.

Happened on Windows 2000 SP4 with gcc-3.4.1-20040711-1, mingw-
runtime-3.3 and win32api-2.5.

I already reported it to the MinGW team
(http://sourceforge.net/tracker/index.php?func=detail&aid=992979&group_id=2435&atid=102435),
but I got no response yet. It was just assigned to dannysmith. Because I got no
Linux to check it for the same problem and because I got no responses, I thought
I might report it directly into GCC bugzilla.

#include <iostream>
#include <stdlib.h>

using namespace std;

class CTest
{
public:
CTest();
~CTest() {}
private:
int _impl;
};

CTest::CTest()
{
try {
_impl = 0;
}catch(...){
}
}

int main(int argc, char *argv[])
{
CTest test;

return 0;
}
Comment 1 Oliver Stoeneberg 2004-08-12 16:03:12 UTC
I posted this as an comment at sf.net, but I think it might also make sense to
post it here:

This code gives me the warning 5 times on line 46. The
interetsing thing is, that if you remove the unused var
"mname" you only get it four times.

#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

bool test()
{
	string result;
	string mname;

	if( result.empty() )
		return false;

	char *tmp = NULL; //(char*)malloc(result.length()+1);	

	char tmpStr[256];
	strcpy(tmpStr, result.c_str());

	tmp = tmpStr;

	char *pos = NULL;

	try {
		pos = strstr(tmp, ".");
		if (pos != NULL) {
			*pos = 0;
			tmp = pos+1;
			pos = strstr(tmp, ".");
			if (pos != NULL) {
				*pos = 0;
				tmp = pos+1;
				pos = strstr(tmp, ".");
				if (pos != NULL) {
					tmp = pos+1;
				}
				else
					return false;
			}
			else
				return false;
		}
		else
			return false;
	}
	catch(...) {
		return false;
	}

	return true;
}

int main(int argc, char *argv[])
{
	bool tmp = test();
	
 	system("PAUSE");
  	return 0;
}
Comment 2 Andrew Pinski 2004-08-13 00:13:01 UTC
Not a bug, as we emit two constructors and this is warning for those two places.