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; }
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; }
Not a bug, as we emit two constructors and this is warning for those two places.