__traits(compiles, ...) with syntax errors

Kagamin spam at here.lot
Tue Jan 15 08:26:33 UTC 2019


On Monday, 14 January 2019 at 21:47:40 UTC, Steven Schveighoffer 
wrote:
> How many times have you written something like:
>
> void foo(T)(T t) if (__traits(compiles, t.bar())) // or 
> is(typeof(t.bar()))
> {
>    t.bar();
> }
>
> And somehow, somewhere, this isn't called? Then you remove the 
> constraint, and find that there's a syntax error in the bar 
> template function (like a missing semicolon).

struct A
{
     int f()()
     {
         return 0
     }
}

Like this? There's no way for it to ever compile.


More information about the Digitalmars-d mailing list