Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad error message when template function with bad parameter type & constraint is instantiated #20693

Open
ichordev opened this issue Jan 13, 2025 · 0 comments

Comments

@ichordev
Copy link
Contributor

Let's say you tried to make a templated function, but one of the parameters' types isn't semantically correct. If you try to instantiate that function then you will only get an error at the point of instantiation telling you that you didn't 'match the template declaration', when you should really be getting an error from the malformed template. Here's an example:

auto templateFn(alias a)(T b)
if(true){}
alias broken = templateFn!("hello!");

Outputs:

Error: template instance `templateFn!"hello!"` does not match
template declaration `templateFn(alias a)(T b)`'

Note that if the constraint if(true) is removed, then the correct error messages are displayed. In this case:

Error: undefined identifier `T`
Error: template instance `templateFn!"hello!"` error instantiating

You can replace T in this example with any semantically incorrect type (i.e. where is(T) == false) and you get the result. It seems like when the parameter type is _error_ it gets silently allowed, and then it causes an error in the template constraint.

@ichordev ichordev changed the title Bad error message when broken template function with constraint is instantiated Bad error message when template function with bad parameter type & constraint is instantiated Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants