Strange behaviour with "shared" function parameters

Maor Ben Dayan via D.gnu d.gnu at puremagic.com
Sun Nov 9 08:44:47 PST 2014


The following program demonstrates a difference between how gdc & 
dmd handle function parameters qualified as shared:

import std.stdio;

void foo(out shared int x) {
   x = 5;
}

void main()
{
   version (works) {
     shared int b = 4;
   } else {
     int b = 4;
   }
   writeln(b);
   foo(b);
   writeln(b);
}

while both 'dmd ./test.d -of/tmp/a.out' and 'dmd -version=works 
./test.d -of/tmp/a.out' output:
4
5

'gdc -fversion=works ./test.d -o /tmp/a.out' prints the right 
output:
4
5

BUT 'gdc ./test.d -o /tmp/a.out' prints:
4
4

I assume this is a bug, right ?

Maor




More information about the D.gnu mailing list