Another level 4 warning compiler bug (C4702)

  • Thread starter J.D. Herron via .NET 247
  • Start date
J

J.D. Herron via .NET 247

Just wanted to throw out there a VC7.1 compiler bug when usingwarning level 4. The following code will demonstrate theproblem:


class TestClass
{
public:
// Initialized float member, generates C4702 warning
TestClass() : m_fValue(1.f)
{
try
{
throw 1;
}
catch ( ... ) // C4702 unreachable code warning issuedhere
{
std::cout
<< "Caught exception in default TestClassconstructor"
<< std::endl;
}
}

// Does not initialize float member, does not generatewarning
TestClass( int p_i )
{
try
{
throw p_i;
}
catch ( ... )
{
std::cout
<< "Caught exception in parameterized TestClassconstructor"
<< std::endl;
}
}

protected:

float m_fValue;
};

int _tmain(int argc, _TCHAR* argv[])
{
TestClass test1;
TestClass test2(2);

char cDelay;
std::cin >> cDelay;

return 0;
}

The default TestClass constructor will generate the C4702"unreachable code" warning at the catch when compiled withwarning level 4, but the parameterized constructor will not. Ithas something to do with initializing the float member as if youtake this away, the warning no longer happens. Running the codedemonstrates that the "unreachable code" in the catch isexecuted. Perhaps a VC developer will see this and make sureits fixed in the 2005 version.
 
D

David Lowndes

Just wanted to throw out there a VC7.1 compiler bug when using warning level 4.

Strange, I've just pasted your code into a VC7.1 console application
and can't reproduce any warning (at /W4).

Dave
 
R

Ronald Laeremans [MSFT]

David said:
Strange, I've just pasted your code into a VC7.1 console application
and can't reproduce any warning (at /W4).

Dave

Did you do a release build? This diagnostic is only emitted when the
optimizer runs.

Ronald
 
D

David Lowndes

Just wanted to throw out there a VC7.1 compiler bug when using warning level 4.
Did you do a release build? This diagnostic is only emitted when the
optimizer runs.

No, I didn't!

As I've pointed out in the past, having consistency in the compiler
between debug and release builds would be beneficial - if only to
prevent some of my public embarrassments :)

Dave
 
B

Bo Persson

David Lowndes said:
No, I didn't!

As I've pointed out in the past, having consistency in the compiler
between debug and release builds would be beneficial - if only to
prevent some of my public embarrassments :)

The problem here, of course, is that you have to run a data flow
analysis to detect some of the problems. If you don't run the optimizer,
you will not notice that it would fail.


Bo Persson
 
R

Ronald Laeremans [MSFT]

As I've pointed out in the past, having consistency in the compiler
The problem here, of course, is that you have to run a data flow
analysis to detect some of the problems. If you don't run the optimizer,
you will not notice that it would fail.


Bo Persson

Yes,

Specifically it would increase compile time, sometimes significantly.

Ronald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top