[Issue 8577] static assert is triggered after tuple bounds check
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 8 08:49:13 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=8577
RazvanN <razvan.nitu1305 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |razvan.nitu1305 at gmail.com
Resolution|--- |INVALID
--- Comment #2 from RazvanN <razvan.nitu1305 at gmail.com> ---
Today, the code yields:
onlineapp.d(2): Error: tuple index 1 exceeds 1
onlineapp.d(7): Error: template instance `onlineapp.T!int` error instantiating
And I am arguing that this is the correct behavior. The static assert is
generally used to test that things inside the template instantiation are
correct.
Template constraints are used to check that the template arguments are correct.
The static assert cannot be evaluated before the template is instantiated
because that will make it useless in 99% of the cases. The general case for
static asserts in template declarations is to check that specific template
properties are correct, therefore, you first need to have the instantiation
before you actually evaluate the static assert.
In conclusion: use template constraints for this scenario:
template T(Ts...)
if (Ts.length > 1)
{
alias Ts[1] Z;
}
Closing as invalid.
--
More information about the Digitalmars-d-bugs
mailing list