August 22, 2011 An issue with templates with non-existant symbols | ||||
---|---|---|---|---|
| ||||
void foo(T)(T t) if(is(X == struct)) { } void main() { foo(4); } This prints out: test.d(9): Error: template test.foo(T) if (is(X == struct)) does not match any function template declaration test.d(9): Error: template test.foo(T) if (is(X == struct)) cannot deduce template function from argument types !()(int) which is your typical template instantiation error. The real issue is that the symbol "X" doesn't actually exist. I've had a template I was refactoring and I've accidentally mistyped the name of the type, e.g.: void foo(T)(T r) if (is(T == struct) || is(t == class)) // t should have been T I was hoping for a better error message here. Can the compiler check that `is` has an expression with valid symbols in it? |
August 22, 2011 Re: An issue with templates with non-existant symbols | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 08/22/2011 04:16 AM, Andrej Mitrovic wrote:
> void foo(T)(T t) if(is(X == struct)) { }
>
> void main()
> {
> foo(4);
> }
>
> This prints out:
>
> test.d(9): Error: template test.foo(T) if (is(X == struct)) does not
> match any function template declaration
> test.d(9): Error: template test.foo(T) if (is(X == struct)) cannot
> deduce template function
> from argument types !()(int)
>
> which is your typical template instantiation error. The real issue is
> that the symbol "X" doesn't actually exist.
>
> I've had a template I was refactoring and I've accidentally mistyped
> the name of the type, e.g.:
>
> void foo(T)(T r) if (is(T == struct) || is(t == class)) // t should have been T
>
> I was hoping for a better error message here. Can the compiler check
> that `is` has an expression with valid symbols in it?
No, because that would defeat the main purpose of 'is'. 'is' is to a large extent there to allow you to check for conditions that are not necessarily semantically valid.
However, the compiler could catch that the result of some parts of the constraint does not actually depend on any template arguments to improve the error message. Maybe you could write an enhancement request for this.
|
Copyright © 1999-2021 by the D Language Foundation