Compiler analysis fault?

DLearner bmqazwsx123 at gmail.com
Wed Dec 20 11:33:22 UTC 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());
}

```


More information about the Digitalmars-d-learn mailing list