D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16313 - Duplicate symbol generated
Summary: Duplicate symbol generated
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-23 07:11 UTC by Jorge Lima
Modified: 2017-11-02 08:58 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jorge Lima 2016-07-23 07:11:35 UTC
The compiler generates duplicated symbols for "my_array" in the following code snippet and causes the linker to fail. 
The issue is triggered by the circular reference in line 18 (which is perfectly legal btw). Commenting that line and the error goes away. This issue is present in 2.071.1 on OSX and windows at least, but not present in version 2.067.1, at least not in OSX or linux.   

01  struct Foo {
02      int a;
03      immutable(Foo[])* b;
04      this(int _a, immutable(Foo[])* _b)
05      {
06          a = _a;
07          b = _b;
08      }
09      this(int _a)
10      {
11          this(_a, null);
12      }
13  };
14
15  immutable Foo[] my_array = [
16      Foo(1),
17      Foo(2),
18      Foo(3, &my_array),
19  ];
20
21  void main()
22  {
23      int a = my_array[0].a;
24  }
Comment 1 Jorge Lima 2016-11-25 16:34:07 UTC
Hello,

I tested the code snippet with dmd-2.072.0 under Linux64bit and the problem is gone (it was still present with dmd-2.071.2). Even though this bug report was never addressed. I will test it under windows and and MacOS asap and will update this report accordingly.

JLima
Comment 2 RazvanN 2017-11-01 14:00:25 UTC
Just tested on Windows with git HEAD and the issue is still present. On Ubuntu 16.04 the issue is not present. Changing description to Windows
Comment 3 Jorge Lima 2017-11-01 22:37:09 UTC
(In reply to RazvanN from comment #2)
> Just tested on Windows with git HEAD and the issue is still present. On
> Ubuntu 16.04 the issue is not present. Changing description to Windows

I tested before with release 2.072.0 and the problem was fixed. See my previous comment from 2016-11-25. However. at the time, I didn't check on all platforms
Triggered by your comment, I tested now the release 2.076.1 on the following platforms

Ubuntu 16.04 64bit: passed 
OS X 10.10: passed
Windows 10 64bit: failed but due to a different issue. See below.

> dmd snippet.d
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
teste.obj(teste)  Offset 00370H Record Type 009D
 Error 16: Index Range
Error: linker exited with status 1

I noticed OPTLINK is for Win32. Weird! So I passed the option -m64 to dmd
to force it to use the microsoft linker.

> dmd -m64 snippet.d

And it compiled the snippet without errors.

So I would say this problem seems to be fixed!
Comment 4 RazvanN 2017-11-02 08:58:41 UTC
(In reply to Jorge Lima from comment #3)
> (In reply to RazvanN from comment #2)
> > Just tested on Windows with git HEAD and the issue is still present. On
> > Ubuntu 16.04 the issue is not present. Changing description to Windows
> 
> I tested before with release 2.072.0 and the problem was fixed. See my
> previous comment from 2016-11-25. However. at the time, I didn't check on
> all platforms
> Triggered by your comment, I tested now the release 2.076.1 on the following
> platforms
> 
> Ubuntu 16.04 64bit: passed 
> OS X 10.10: passed
> Windows 10 64bit: failed but due to a different issue. See below.
> 
> > dmd snippet.d
> OPTLINK (R) for Win32  Release 8.00.17
> Copyright (C) Digital Mars 1989-2013  All rights reserved.
> http://www.digitalmars.com/ctg/optlink.html
> teste.obj(teste)  Offset 00370H Record Type 009D
>  Error 16: Index Range
> Error: linker exited with status 1
> 
> I noticed OPTLINK is for Win32. Weird! So I passed the option -m64 to dmd
> to force it to use the microsoft linker.
> 
> > dmd -m64 snippet.d
> 
> And it compiled the snippet without errors.
> 
> So I would say this problem seems to be fixed!

Cool! I had the same error weird error and I thought that was the issue. Thanks a lot. Closing as fixed