erroneous 'unreachable code' warning in a throw statement?

  • Thread starter Thread starter Hovik Melikyan
  • Start date Start date
H

Hovik Melikyan

This code produces a 'unreachable code' warning at line 16 (throw new X ...)
with no visible reason:


#include <string>


class X
{
std::string msg;
public:
X(const std::string& imsg): msg(imsg) {}

std::string get_msg() { return msg; }
};


void f()
{
throw new X("The program made a boo-boo");
}


int main()
{
try
{
f();
}
catch (X* x)
{
delete x;
}
return 0;
}



The warning disappears as soon as I remove the operator new in the throw
statement OR make the X constructor accept (const char*) instead of (const
string&). So dynamic allocation and the dynamic string together confuse the
..NET compiler.

I looked at the assembly code and found nothing that can be left out (i.e.
no `unreachable code') when an exception is thrown. Also, no memory leaks
seem to occur.

GCC does not give any warnings.

Can anyone explain if this warning message is erroneous or it really warns
of a potential bug?

Thanks,
 
Hovik said:
Can anyone explain if this warning message is erroneous or it really
warns of a potential bug?

It's a bug in the compiler (I reproduced it using VC7.1). It appears to be
fixed in the Whidbey alpha.

-cd
 
-----Original Message-----


It's a bug in the compiler (I reproduced it using VC7.1). It appears to be
fixed in the Whidbey alpha.

We got hundreds of similar warnings when recompiling
using .NET 2003. My suspicion is that this is exactly the
same bug, which is why it's already fixed.
 
Back
Top