Bug 43344 - -Wunreachable-code incorrect warning
Summary: -Wunreachable-code incorrect warning
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-12 12:26 UTC by Jiri Engelthaler
Modified: 2010-03-12 12:29 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 Jiri Engelthaler 2010-03-12 12:26:57 UTC
By adding a destructor to main class to example in the bug 21228 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21228) will produce incorrect warning about code that "will never be executed"

# g++  -Wunreachable-code gstest.cpp
gstest.cpp: In constructor ‘testString::testString()’:
gstest.cpp:24: warning: will never be executed
gstest.cpp: In constructor ‘testString::testString()’:
gstest.cpp:24: warning: will never be executed

#cat gstest.cpp
// #include <stdio.h>

class testStringBase
{
public:
  ~testStringBase();
  char *stringPtr;
};

testStringBase::~testStringBase()
{
  stringPtr = 0;
}

class testString : public testStringBase
{
public:
  testString();
};

testString::testString()
{
  stringPtr = (char *) 9;
}

int main(int argc, char **argv) {
  testString s;
  //  printf("s.stringPtr is %ld\n", (unsigned long) s.stringPtr);
}
Comment 1 Richard Biener 2010-03-12 12:29:23 UTC
-Wunreachable-code is broken and has been removed from GCC 4.5.  Do not use it.