Article ID: 150884
Article Last Modified on 7/5/2005
// Compile option needed are: /GX, /W4, and /O1(minimize size)
// or /O2 (maximize speed)
struct A
{
~A(){}
};
struct B
{
A a;
};
void main(void)
{
try // line 17
{
B *pB = new B[4];
delete [] pB; // line 20, warning C4702: unreachable code
}
catch(...)
{
}
}
The following error message is generated:
Compiling from command line with both /Og (global optimizations) and
in-line function expansion, /Ob1(Only __inline) or /Ob2 (Any Suitable),
reproduces the error. For instance, using:
cl /Og /Ob1 /GX /W4 test.cppCompiling with the following switch settings in command line does not produce errors:
cl /Og /GX /W4 test.cpp- or -
cl /Ob1 /GX /W4 test.cppOne workaround when using /O1 or /O2 in Developer Studio is to disable In-line function expansion (Build:Settings, C++ Tab, Optimizations category). Another workaround is to disable global optimizations. To accomplish this, choose Custom for the type of optimization (Build:Settings, C++ Tab, Optimizations category). Check all categories that apply, but do not check global optimizations. This behavior is similar to using the components of /O1 or /O2 and eliminating /Og). An additional method is to leave /O1 or /O2 intact and manually add /Og- to the Project Options.
Additional query words: kbVC400bug 4.00 4.10 4.20 vcfixlist420 CPPIss
Keywords: kbbug kbfix kbcpponly kbcompiler KB150884