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.
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.