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,
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,