__traits(compiles, ...) with syntax errors
Steven Schveighoffer
schveiguy at gmail.com
Wed Jan 16 14:31:02 UTC 2019
On 1/15/19 3:26 AM, Kagamin wrote:
> 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.
Indeed, I realized after posting [1] that it's really stupid typos that
I make that are still valid syntax, but obviously unintentional. By that
I mean, it will never compile.
Like:
void foo(T)(T t)
{
int x = 1;
t.fun(X);
}
What I was trying to say is that I wanted a way to separate "obvious"
errors from errors that happen because of the template parameters. But I
think there simply isn't a way to do it. The best we can do might be to
try and force specific instantiations to see why they don't compile.
-Steve
[1] https://forum.dlang.org/post/q1jequ$r63$1@digitalmars.com
More information about the Digitalmars-d
mailing list