Are there any default dmd optimizations

Walter Bright newshound2 at digitalmars.com
Thu Feb 28 18:49:21 PST 2013


On 2/28/2013 3:07 PM, Timon Gehr wrote:
> On 03/01/2013 12:01 AM, Walter Bright wrote:
>> On 2/28/2013 11:03 AM, Timon Gehr wrote:
>>> It's really easy. DMD can be convinced to do a sufficient[ly] conservative
>>> analysis
>>> even now, but the behaviour is undocumented and seems unintentional.
>>>
>>>
>>>      void main() {
>>>          void foo()() { bar(); }
>>>          void bar()() { i = 3; }
>>>          int i;
>>>          foo();
>>>      }
>>
>> No, the compiler is not being clever here,
>
> I wasn't stating that.
>
>> nor is this undocumented.
>
> Where is it documented?

Under templates, it says that templates are instantiated in the scope of the 
corresponding template declaration.

At the time of foo(); bar has been added to the scope.


> Obviously. In the above code all templates are instantiated. This is about which
> state of the function local symbol table is used.

C++ has the notion of point of instantiation and point of definition, with D, 
it's about scope of instantiation and scope of definition instead.


More information about the Digitalmars-d mailing list