Bug 6089 – __gshared with not static 2D array

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-06-02T07:21:00Z
Last change time
2013-03-19T00:19:43Z
Keywords
pull, rejects-valid
Assigned to
andrej.mitrovich
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-06-02T07:21:24Z
With DMD 2.053 this program: void main() { __gshared int[1][1] foo; } Gives: test.d(2): Error: cannot implicitly convert expression (0) of type int to int[1u][1u]
Comment #1 by ibuclaw — 2011-06-27T14:09:17Z
Similarly, this should be valid code. void main() { __thread int[1][1] foo; } and this shouldn't try to assign a default initialiser at all! void main() { extern int[1][1] foo; }
Comment #2 by andrej.mitrovich — 2013-03-18T08:00:02Z
(In reply to comment #0) > With DMD 2.053 this program: > > > void main() { > __gshared int[1][1] foo; > } This is fixed by Issue 8041. (In reply to comment #1) > Similarly, this should be valid code. > > void main() > { > __thread int[1][1] foo; > } __thread has since been removed. > and this shouldn't try to assign a default initializer at all! > > void main() > { > extern int[1][1] foo; > } What exactly are the semantics of this? It has D mangling, so where can you define (not declare) foo? I guess you could use mangling hacks such as: extern(C) int[1][1] D4test4mainFZv3fooG1G1i = [[4]]; void main() { extern int[1][1] foo; assert(foo == [[4]]); } Is this ok though? Note that declaring `extern(C) int[1][1] foo;` does already work.
Comment #3 by andrej.mitrovich — 2013-03-18T08:10:41Z
Comment #4 by ibuclaw — 2013-03-18T08:11:35Z
(In reply to comment #2) > (In reply to comment #0) > > With DMD 2.053 this program: > > > > > > void main() { > > __gshared int[1][1] foo; > > } > > This is fixed by Issue 8041. > > (In reply to comment #1) > > Similarly, this should be valid code. > > > > void main() > > { > > __thread int[1][1] foo; > > } > > __thread has since been removed. > > > and this shouldn't try to assign a default initializer at all! > > > > void main() > > { > > extern int[1][1] foo; > > } > > What exactly are the semantics of this? It has D mangling, so where can you > define (not declare) foo? I guess you could use mangling hacks such as: > > extern(C) int[1][1] D4test4mainFZv3fooG1G1i = [[4]]; > > void main() > { > extern int[1][1] foo; > assert(foo == [[4]]); > } > > Is this ok though? > > Note that declaring `extern(C) int[1][1] foo;` does already work. I don't think it should be valid at all to declare an 'extern' variable/function inside another function. Reasons because of the hairiness as you've described. Just my opinion though.
Comment #5 by github-bugzilla — 2013-03-19T00:00:47Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0503a9eea91e05d74d0a2a4701a7cd50b806c98b Fixes Issue 6089 - extern variable should not have an initializer. https://github.com/D-Programming-Language/dmd/commit/f6adf56c67498de17c5a374a04ab50118cda7cc3 Merge pull request #1762 from AndrejMitrovic/Fix6089 Issue 6089 - extern variable should not have an initializer.