More bugs...

Timon Gehr timon.gehr at gmx.ch
Sat Apr 28 04:28:20 PDT 2012


On 04/28/2012 12:05 PM, Max Samukha wrote:
> 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.
>

"Semantic analysis is not done until instantiated."

On second thought, you are right, this is really badly phrased and does 
not say what it probably wants to. Anyway, the fact that templates are 
analysed fully eagerly upon instantiation is by design and the 
documentation should explicitly state that.

>>
>>> 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.

If we are talking about the same thing, then it probably is not. I 
thought you were proposing to automatically templatise the function iff 
there is recursion?

> Non-templated functions are a special (degenerate) case of templated functions.

How to 'instantiate' a non-templated function? This would necessarily be 
a supported operation, if there actually was such a relation between the 
two concepts.

> The way virtual functions work doesn't allow C++/D to fully implement that notion.

That implies that the notion does not have merit. In D it was left out 
by design. And even C++ does not consistently implement it for non-virtuals.

> Mark f() 'virtual' in the C++ example and the code won't compile.

I know. Furthermore, add an invalid member function to the templated 
struct F and don't refer to it. There won't be any compile time error. 
(unless it is virtual, of course!)

> Otherwise, C++ tries to be close to the ideal

IMAO, it fails to be close to the ideal.

> and I would expect D be no worse.
>

Yah, and it really is not.

The other issue you brought up in this thread is certainly a real issue 
with the implementation though.


More information about the Digitalmars-d mailing list