How to verify that a method always returns a value

I wrote a compiler that already works decently. It checks that all non-void methods have at least one return statement, but it does not check whether all code paths in the non-void method return a value. So, for example, if I have the following code:

int function(bool a) 
{
     if(a){
         return 5;
     }
}

It will compile a “fine”, and if a is false, the control will disable the function and continue to execute what is defined in the function.

Is there any algorithm I can use to perform this check so that I always know if the method always returns a value? Or do I need to invent a wheel?

+4
source share
1 answer

" " , , . , return , ( , ), .

, -void-, :

  • return .

  • return , .

  • Typechecking , return, , , . ( , return , void.)

return , . .

, , no-value return ​​, .

+1

All Articles