static assert not printing out along the error diagnostic

jfondren julian.fondren at gmail.com
Wed Jul 14 19:00:08 UTC 2021


On Wednesday, 14 July 2021 at 18:04:44 UTC, someone wrote:
> On Wednesday, 14 July 2021 at 06:28:37 UTC, jfondren wrote:
>
>> alternate 1:
>> - pull tests out into a named enum template, like std.traits
>> - always static assert enum, rather than conditionally 
>> asserting false
>> - always have the rest of the code
>>
>> ```d
>> enum isString(T) = is(T == string) || is(T == wstring) || is(T 
>> == dstring);
>> // very similar to std.traits.isSomeString
>>
>> struct gudtUGC(T) {
>>     static assert(isString!T, "error message");
>>     // unconditional structure code
>> }
>> ```
>
> ... is it me or this isn't triggering the assert either ?

This isn't a complete example. The same problem elsewhere in your 
program can cause dmd to exit before getting to the static assert 
here, for the same reason that the static assert in your original 
code wasn't got to.

Here's a complete example:

```d
enum isString(T) = is(T == string) || is(T == wstring) || is(T == 
dstring);

struct gudtUGC(T) {
     static assert(isString!T, "error message");
     // unconditional structure code
}

unittest {
     gudtUGC!int;
}
```

which fails with

```
example.d(4): Error: static assert:  "error message"
example.d(9):        instantiated from here: `gudtUGC!int`
```

If you have the static assert there but then still follow up with 
static ifs that only conditionally produce an alias, then you 
have the same problem still.


More information about the Digitalmars-d-learn mailing list