473,586 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1982
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
315
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 after the Using statement gives a compiler warning of "Unreachable Code Detected", and it never runs. Why is this happening? I really don't want to...
4
2825
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 this ? C++ exceptions are enabled ( /EHsc ). Thanks. SS
6
27528
by: dfetrow410 | last post by:
Can I do this in an if statement? public string getClass() { counta = counta + 1; if (counta < 2 ) {
4
6970
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
1714
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
3292
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"); Looks valid to me, but this gives a warning with "new" underlined saying "warning CS0429: Unreachable expression code detected".
5
1869
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 included below. I got the same results with GCC 3.4.4 under cygwin as with MSDev studio 2003. Even stranger to me, if I change the catch statement to...
4
6162
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; public class Graph { ArrayList<ArrayList<Integer>> graph; public void Graph( int n )
1
2503
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 possibly be done after the return statement hence the break statement will not and can ever be reached? switch (suffix) { case 1: return...
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.