More bugs...
Max Samukha
maxsamukha at gmail.com
Sat Apr 28 03:05:04 PDT 2012
On Saturday, 28 April 2012 at 09:40:49 UTC, Timon Gehr wrote:
> On 04/28/2012 09:46 AM, Max Samukha wrote:
>> On Saturday, 28 April 2012 at 06:03:54 UTC, Mehrdad wrote:
>>>> You expected that to work?
>>>
>>> Uhm, why not?
>>>
>>> template<class T>
>>> struct F
>>> {
>>> F<F<T> > f() { return F<F<T> >(); }
>>> };
>>>
>>> int main()
>>> {
>>> F<int>().f().f().f().f().f(); // etc.
>>> return 0;
>>> }
>>>
>>
>> dmd is not smart enough
>
> DMD behaves according to the language specification here.
That is not specified anywhere in the language specification.
>
>> to avoid recursion by treating f as a
>> templated function. I am not sure whether it should,
>
> Maybe, but that would be a strange special case.
That is arguable. Non-templated functions are a special
(degenerate) case of templated functions. The way virtual
functions work doesn't allow C++/D to fully implement that
notion. Mark f() 'virtual' in the C++ example and the code won't
compile. Otherwise, C++ tries to be close to the ideal and I
would expect D be no worse.
>
>> but the following should certainly work:
>>
>> struct F(T)
>> {
>> auto f()() { return F!(F!T)(); }
>> }
>>
>> void main()
>> {
>> F!int().f().f().f();
>> }
>>
>> Error: struct a.F(T) recursive template expansion for template
>> argument - why?
>>
>
> The checking for infinite recursion seems to be too
> conservative here. You could open a bug report.
More information about the Digitalmars-d
mailing list