[Issue 16665] static assert is only checked after the following dependent type declaration

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 12 13:53:17 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=16665

Manu <turkeyman at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |turkeyman at gmail.com
           Severity|normal                      |major

--- Comment #4 from Manu <turkeyman at gmail.com> ---
druntime and phobos are riddled with this issue!

static assert needs to tell you the error it's checking for _before_ the errors
relating to the symptoms of the error it's checking for, otherwise it's
useless.

In druntime, all the cases like:

```
version (Posix)
    public import core.sys.posix.stdc.time;
else version (Windows)
    public import core.sys.windows.stdc.time;
else
    static assert(0, "unsupported system");

@system time_t  mktime(scope tm* timeptr);
```

1> time.d(37): error : undefined identifier `tm`

The static assert doesn't emit any error message at all!
It's difficult to imagine how the compiler could be certain that `tm` is not a
thing before it's able to resolve `assert(0)`. The version sequence can be
resolved immediately, and static assert(0) can be resolved immediately too...

This is actually a pretty serious bug; we can't write portable code if we can't
expect top-level static assert's to inform us that symbols are missing or that
a platform is not supported!

--


More information about the Digitalmars-d-bugs mailing list