Thread overview
maybe a noreturn issue
Dec 03
Basile B.
Dec 03
Basile B.
Dec 03
Dennis
December 03

Not sure if that should compile

int f()
{
    while (true) {}
}

What I observe and think right now is:

  1. if you remove the while statement, you get an error about return statement missing
  2. here the compiler detects that f while not return, in consequence it should not accept the input and says that f return type should be noreturn.

What's you're position ?

December 03

On Tuesday, 3 December 2024 at 12:41:18 UTC, Basile B. wrote:

>

Not sure if that should compile

int f()
{
    while (true) {}
}

What I observe and think right now is:

  1. if you remove the while statement, you get an error about return statement missing
  2. here the compiler detects that f while not return, in consequence it should not accept the input and says that f return type should be noreturn.

What's you're position ?

"f will not return"

to avoid any misunderstanding.

December 03

On Tuesday, 3 December 2024 at 12:41:18 UTC, Basile B. wrote:

>

What's you're position ?

I often see suggestions to raise warnings/errors for ostensibly 'useless constructs', such as unused parameters, if (0), strongly pure functions returning void etc.

In my experience, doing this rarely catches any actual bugs. Instead you'll end up bumping into such warnings/errors as annoying false positives, and then you realise that these constructs are, in fact, useful at times.

For example, unused parameters (and unnecessarily loose return types) can turn up when:

  • The signature needs to match a callback (e.g. a thread function may not return, even though the signature allows returning a status code)
  • A parameter / return value is no longer needed / reserved for future use, but signature is part of stable API
  • int f(int x) => assert(0, "unimplemented");

So I'm not a fun of such a rule.

December 03

On Tuesday, 3 December 2024 at 12:41:18 UTC, Basile B. wrote:

>

Not sure if that should compile

int f()
{
    while (true) {}
}

The spec allows that:
https://dlang.org/spec/function.html#function-return-values