[Issue 13575] Unreachable scope(failure) should be warned

2023-11-14 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13575

Steven Schveighoffer  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||schvei...@gmail.com
 Resolution|--- |INVALID

--- Comment #3 from Steven Schveighoffer  ---
You can no longer return from scope(failure)

--


[Issue 13575] Unreachable scope(failure) should be warned

2022-12-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13575

Iain Buclaw  changed:

   What|Removed |Added

   Priority|P1  |P4

--


[Issue 13575] Unreachable scope(failure) should be warned

2020-01-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13575

--- Comment #2 from Witold Baryluk  ---
Ah, obviously I did forgot to mention that compiler does not warn about my
first example.

But it should.

--


[Issue 13575] Unreachable scope(failure) should be warned

2020-01-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=13575

Witold Baryluk  changed:

   What|Removed |Added

 CC||witold.barylu...@gmail.com

--- Comment #1 from Witold Baryluk  ---
Your example is pretty good, but not good enough as it introduces other issue,
that prevents compiler from optimizing it properly.

The writeln("Failed in someFunc()") can fail with the exception (i.e. if the
stdout was a pipe into other process, and that process died, or it was
redirected to a file, and there was IO error or disk is full / out of quota,
just some examples)! And then the first scope(failure) which can in fact
execute!


Better example:


```
int i = 0;

size_t f(string x) nothrow {
  scope(failure) {
i = 5;
return 30;
  }
  scope(failure) {
i = 10;
return 42;
  }
  throw new Exception("a");
}

int main(string[] args) {
  return cast(int)f(args[0]) + i*i;
}
```

Notice that I also added `nothrow` and made scopes use code that can't throw on
its own.

The compiler doesn't even recognize that the first `scope(failure)` is not dead
code. I still see it in the disassembly of the binary.


When I run the code it does return 142, as expected.

If I change the code to:

```
int i = 0;

size_t f(string x) nothrow {
  scope(failure) {
i = 5;
return 30;
  }
  scope(failure) {
i = 10;
throw new Exception("b");
  }
  throw new Exception("a");
}

int main(string[] args) {
  return cast(int)f(args[0]) + i*i;
}
```

The code correctly returns 55.

--