www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - what happened to the reachability diag ?

reply Basile B. <b2.temp gmx.com> writes:
I've been away of D since a while but I'm surprised to see DMD 
accepting this input without any **warning**s

```d
module runnable;

void main() nothrow  // no landing pad
{
     enum E {e0}
     E e;
     final switch (e)
     {
         case E.e0: goto case E.e0;
     }
     return; // statement not reachable
}

void other() nothrow // no landing pad
{
     enum E {e0}
     E e;
     final switch (e)
     {
         case E.e0: goto case E.e0;
     }
     int a; // declaration not reachable
}

int shoudlebeLike()
{
     assert(0)  ;
     while (true)
     {
         other();
     }
     assert(0);
     other();
     return 0;
}
```

(tried with -w -wi, etc).
Dec 10
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
It was removed.

Its dead code, not hurting anyone, and just being plain annoying with 
templates.
Dec 10
parent reply Basile B. <b2.temp gmx.com> writes:
On Wednesday, 10 December 2025 at 15:32:39 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 It was removed.

 Its dead code, not hurting anyone, and just being plain 
 annoying with templates.
at least `main()` is a problem. Obviously the examples are catchy on purpose. Prepare a console and killall. Seriously I don't get your argument.
Dec 10
next sibling parent reply Kapendev <alexandroskapretsos gmail.com> writes:
On Wednesday, 10 December 2025 at 15:54:15 UTC, Basile B. wrote:
 On Wednesday, 10 December 2025 at 15:32:39 UTC, Richard (Rikki) 
 Andrew Cattermole wrote:
 It was removed.

 Its dead code, not hurting anyone, and just being plain 
 annoying with templates.
at least `main()` is a problem. Obviously the examples are catchy on purpose. Prepare a console and killall. Seriously I don't get your argument.
It’s easy to use `static if`s or `mixin`s in a way that produce something functionally equivalent to what you wrote. The way things work currently makes it easier to do metaprogramming. In practice this is not an issue even for "normal" code.
Dec 10
parent reply Basile B. <b2.temp gmx.com> writes:
On Wednesday, 10 December 2025 at 16:07:13 UTC, Kapendev wrote:
 On Wednesday, 10 December 2025 at 15:54:15 UTC, Basile B. wrote:
 On Wednesday, 10 December 2025 at 15:32:39 UTC, Richard 
 (Rikki) Andrew Cattermole wrote:
 It was removed.

 Its dead code, not hurting anyone, and just being plain 
 annoying with templates.
at least `main()` is a problem. Obviously the examples are catchy on purpose. Prepare a console and killall. Seriously I don't get your argument.
It’s easy to use `static if`s or `mixin`s in a way that produce something functionally equivalent to what you wrote. The way things work currently makes it easier to do metaprogramming. In practice this is not an issue even for "normal" code.
no template, no metaprog, no mixin, involved here. You're going into Richard answer. Point is just "very simply" that you should get a warning here.
Dec 10
next sibling parent monkyyy <crazymonkyyy gmail.com> writes:
On Wednesday, 10 December 2025 at 17:53:18 UTC, Basile B. wrote:
 On Wednesday, 10 December 2025 at 16:07:13 UTC, Kapendev wrote:
 On Wednesday, 10 December 2025 at 15:54:15 UTC, Basile B. 
 wrote:
 [...]
It’s easy to use `static if`s or `mixin`s in a way that produce something functionally equivalent to what you wrote. The way things work currently makes it easier to do metaprogramming. In practice this is not an issue even for "normal" code.
no template, no metaprog, no mixin, involved here. You're going into Richard answer. Point is just "very simply" that you should get a warning here.
your in an extreme minority here im pretty sure, 85%ish was in favor
Dec 10
prev sibling parent reply Kapendev <alexandroskapretsos gmail.com> writes:
On Wednesday, 10 December 2025 at 17:53:18 UTC, Basile B. wrote:
 no template, no metaprog, no mixin, involved here. You're going 
 into Richard answer. Point is just "very simply" that you 
 should get a warning here.
I don't know who "Richard" is. Warnings are helpful when they actually prevent something serious. As I already said:
 In practice this is not an issue even for "normal" code.
Dec 10
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 11/12/2025 8:04 AM, Kapendev wrote:
 On Wednesday, 10 December 2025 at 17:53:18 UTC, Basile B. wrote:
 no template, no metaprog, no mixin, involved here. You're going into 
 Richard answer. Point is just "very simply" that you should get a 
 warning here.
I don't know who "Richard" is. Warnings are helpful when they actually prevent something serious. As I already said:
Me :P
Dec 10
prev sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 11/12/2025 4:54 AM, Basile B. wrote:
 On Wednesday, 10 December 2025 at 15:32:39 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 It was removed.

 Its dead code, not hurting anyone, and just being plain annoying with 
 templates.
at least `main()` is a problem. Obviously the examples are catchy on purpose. Prepare a console and killall. Seriously I don't get your argument.
If that is instantiated with an int for the type, it errored. This happened enough that it was on peoples hit list as a false positive nearing 100% of the time they got it. ```d void func(T)() { static if (is(T = int)) { assert(0); } writeln("hello"); } ``` ----------------------------- In your example, infinite loops can be valid and desirable things. If you want to catch that it should be done with a static analyzer, not as part of the compiler. It will get optimized to: ``` _Dmain: .Lfunc_begin0: .cfi_startproc .p2align 4, 0x90 .LBB0_1: jmp .LBB0_1 .Lfunc_end0: .size _Dmain, .Lfunc_end0-_Dmain .cfi_endproc ``` Compilers keep these loops for a reason.
Dec 10