On Sat, Jun 13, 2020 at 2:05 PM Walter Bright via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
On 6/12/2020 8:25 PM, Andrei Alexandrescu wrote:
> On 6/12/20 8:54 PM, Walter Bright wrote:
>> On 6/12/2020 5:17 PM, Andrei Alexandrescu wrote:
>>> Not sure about that part - if linkage was static by means of using the
>>> "static" keyword, multiple definitions may not be merged. (I may be wrong,
>>> please correct me.) Consider:
>>>
>>> static inline int fun() {
>>>      static int x;
>>>      return ++x;
>>> }
>>>
>>> In C++, each translation unit containing a definition of fun() will have a
>>> distinct address for x. I don't see how the bodies of those functions can be
>>> merged.
>>
>> They are not merged in D, for the simple reason that ModuleA.fun() and
>> ModuleB.fun() will have different (mangled) names presented to the linker.
>
> For D the question is if they are merged if the function is defined in a .di
> file and imported in two other modules.

If the di file is mentioned on the command line to the compiler

It's not, that's literally the point of a .di file.
 
, yes (1)
instance of it appears in the executable. Otherwise, (0) instances of it appear
in the executable. There are never 2 or more instances in the executable.

Exactly. And this is not a useful design.