December 20, 2023

The code below fails to compile with
Error: function test1.foo no return exp; or assert(0); at end of function
unless the commented-out assert(0) is included.

Please, what rule of D is being broken?
foo does not unconditionally loop, and the only places where foo returns, it returns with a bool.

bool foo() {
   import std.stdio;
   int I1;
   int nogoagain;

   while(true) {

      I1 = 2;
      while( I1 <= 10) {

         if (I1 != 5) {
         } else {
             goto L2;
         }
         I1 = I1 + 1;
      }
      return true;


      L2:;
      readf(" %s", nogoagain);
      if (nogoagain == 5) {
         return false;
      } else {
      }
   }
//   assert(0);
}


void main() {

   import std.stdio;

   writeln("A");

   writeln(foo());
}

December 20, 2023

On Wednesday, 20 December 2023 at 11:33:22 UTC, DLearner wrote:

>

The code below fails to compile with
Error: function test1.foo no return exp; or assert(0); at end of function
unless the commented-out assert(0) is included.

The compiler basically gives up control flow analysis when encountering a goto statement or labeled break/continue.

bool foo()
{
   while(true)
   {
        L2:
        goto L2;
   }
//   assert(0);
}