473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

erroneous 'unreachable code' warning in a throw statement?


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
2 1966
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
-----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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kepler | last post by:
I have a situation where I need to use a Using statement that creates some records in a database. After that completes, if it completes, I need to do some file creation. Any code I'm putting...
4
by: SteadySteps | last post by:
Hi I migrated a project which compiles correctly on VC 6.0 to VS 2002. However now all I get several warning that all the statements within catch blocks are "unreachable code". How can I correct...
6
by: dfetrow410 | last post by:
Can I do this in an if statement? public string getClass() { counta = counta + 1; if (counta < 2 ) {
4
by: Gernot Frisch | last post by:
I get informed that parts of my code cannot be reached. Did I do something wrong? try { if (login(progstring) > 0) { return 1; // OK } }
1
by: tam | last post by:
when i am using session variable i found one error that unreachable core error. how to rectify this error
3
by: Don Burden | last post by:
We've started converting some applications to the .NET 2.0 framework. When compiling in VS 2005, I'm getting a warning on this line: return (unitWidth != null ) ? unitWidth : new Unit("0px"); ...
5
by: stevewilliams2004 | last post by:
I was wondering if someone could explain the output I am getting for the program below. What I expected from the main program output was "Cat" but instead I see "Mammal". The output is also...
4
by: EmilyA | last post by:
Hi! I'm not that good at programming, so I was wondering if anyone could tell me why I'm getting an unreachable statement error for lines 18, 35, 68, and 86. import java.util.ArrayList; ...
1
by: HillBilly | last post by:
What does that error mean and why would each break statement be marked as unreachable? It implies the return will --always-- return some --thing-- if even null and no further processing can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.