By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 2,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

erroneous 'unreachable code' warning in a throw statement?

P: n/a

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 Melikyan


Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hovik Melikyan wrote:
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
Nov 16 '05 #2

P: n/a
-----Original Message-----
Hovik Melikyan wrote:
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 befixed 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.
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.