Potential Managed C++ bug - missing return statement allowed

  • Thread starter Thread starter Brian Kelly
  • Start date Start date
B

Brian Kelly

Hi all,

The following code unfortunately compiles fine with VC++ 7.1 and the
/clr switch:

System::Type*
foo()
{
if (0)
{
throw 1;
}
}

Rather than throw a syntax error of "foo() must return a value", it
instead compiles fine and has the less-than-desirable implicit
behaviour of returning a null Type*. If you remove the "throw"
statement, the syntax error is caught by the compiler.

Can anyone confirm or deny? If this is a known bug already, is there a
planned fix date?

Thanks in advance!

Best regards,
Brian
 
Hmmm, I created a Managed C++ console app and this code below :-

__gc class Test
{
public:
System::Type* foo()
{
if (0)
{
throw 1;
}
}

};

gave me :-

c:\.....cpp(19): error C2561: 'Test::foo' : function must return a value

I used VC++ 7.1 too!
 
Back
Top