digitalmars.D.learn - Some testing?
- bearophile (7/7) Jul 14 2010 This small D2 program compiles with no errors:
- Jonathan M Davis (5/17) Jul 14 2010 You get an error if you use foo. My guess would be that foo effectively ...
- Mafi (6/11) Jul 14 2010 Imagine T was void. Then no return was ok. It wouldn't (shouldn't)
- bearophile (10/14) Jul 14 2010 You are right, this different version runs:
- Don (7/17) Jul 14 2010 Yes, it'd be possible for such simple cases, but would it be worthwhile?
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
Jul 14 2010
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, bearophileYou 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
Jul 14 2010
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
Jul 14 2010
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
Jul 14 2010
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, bearophileYes, 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.
Jul 14 2010