Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 14, 2010 Some testing? | ||||
---|---|---|---|---|
| ||||
This small D2 program compiles with no errors: T foo(T)(T x) {} void main() {} But there is no way it can compile, regardless of the type T, because foo()() lacks a return statement. So is it possible for the D compiler to perform some sanity tests for the template functions too, to catch a bugs like this one? Bye, bearophile |
July 14, 2010 Re: Some testing? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Wednesday, July 14, 2010 11:55:57 bearophile wrote:
> This small D2 program compiles with no errors:
>
> T foo(T)(T x) {}
> void main() {}
>
> But there is no way it can compile, regardless of the type T, because foo()() lacks a return statement. So is it possible for the D compiler to perform some sanity tests for the template functions too, to catch a bugs like this one?
>
> Bye,
> bearophile
You get an error if you use foo. My guess would be that foo effectively doesn't exist until you instantiate it, so there's not really a function to give you an error on.
- Jonathan M Davis
|
July 14, 2010 Re: Some testing? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | Am 14.07.2010 20:55, schrieb bearophile:
> This small D2 program compiles with no errors:
>
> T foo(T)(T x) {}
> void main() {}
>
> But there is no way it can compile, regardless of the type T, because foo()() lacks a return statement.
> So is it possible for the D compiler to perform some sanity tests for the template functions too, to catch a bugs like this one?
Imagine T was void. Then no return was ok. It wouldn't (shouldn't) compile anyways because a parameter of type void is (should be) invalid. However to enforce the compiler to see that T can't be void is a bit to complicated, I think.
Mafi
|
July 14, 2010 Re: Some testing? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | bearophile wrote:
> This small D2 program compiles with no errors:
>
> T foo(T)(T x) {}
> void main() {}
>
> But there is no way it can compile, regardless of the type T, because foo()() lacks a return statement. So is it possible for the D compiler to perform some sanity tests for the template functions too, to catch a bugs like this one?
>
> Bye,
> bearophile
Yes, it'd be possible for such simple cases, but would it be worthwhile?
Since an error message will occur for ANY instantiation of foo, the only errors that would catch are when there's absolutely no testing or use of foo. In which case you have much bigger problems.
And unfortunately it doesn't scale to more complex situations where it might actually help.
|
July 14, 2010 Re: Some testing? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mafi | Mafi:
> Imagine T was void. Then no return was ok. It wouldn't (shouldn't) compile anyways because a parameter of type void is (should be) invalid. However to enforce the compiler to see that T can't be void is a bit to complicated, I think.
You are right, this different version runs:
T foo(T)() {}
void main() {
foo!void();
}
Thanks for all the answers, to you, Don and Jonathan.
A question like this was probably more at home in the IRC channel.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation