www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13167] New: Link errors with std.variant

https://issues.dlang.org/show_bug.cgi?id=13167

          Issue ID: 13167
           Summary: Link errors with std.variant
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: andrei erdani.com

Consider (also http://dpaste.dzfl.pl/051bb1357bba):

import std.variant;

alias Payload = Algebraic!(
    bool,
    double,
    string
);

struct Value
{
    private Payload payload;
    this(T)(T v) { payload = Payload(v); }
    bool opEquals(T)(auto ref T v) { return payload == v; }
}

void main() {}

This code causes the following link errors:

Undefined symbols for architecture x86_64:
 
"_D3std7variant71__T8VariantNVmi16TnTbTdTAyaTAS3std7variant4ThisTHAyaS3std7variant4ThisZ8VariantN06__ctorMFNcNeS3bug5ValueZS3std7variant71__T8VariantNVmi16TnTbTdTAyaTAS3std7variant4ThisTHAyaS3std7variant4ThisZ8VariantN",
referenced from:
      _D3bug5Value23__T6__ctorTS3bug5ValueZ6__ctorMFNcNfS3bug5ValueZS3bug5Value
in bug.o
 
"_D3std7variant71__T8VariantNVmi16TnTbTdTAyaTAS3std7variant4ThisTHAyaS3std7variant4ThisZ8VariantN08opEqualsMxFNbNeKS3bug5ValueZb",
referenced from:
      _D3bug5Value25__T8opEqualsTS3bug5ValueZ8opEqualsMFNfKS3bug5ValueZb in
bug.o

After passing through ddemangle:

Undefined symbols for architecture x86_64:
  "ref  trusted std.variant.VariantN!(16uL, bool, double,
immutable(char)[]).VariantN std.variant.VariantN!(16uL, bool, double,
immutable(char)[]).VariantN.__ctor(bug.Value)", referenced from:
      ref  safe bug.Value bug.Value.__ctor!(bug.Value).__ctor(bug.Value) in
bug.o
  "const(nothrow  trusted bool function(ref bug.Value))
std.variant.VariantN!(16uL, bool, double,
immutable(char)[]).VariantN.opEquals", referenced from:
       safe bool bug.Value.opEquals!(bug.Value).opEquals(ref bug.Value) in
bug.o

Commenting out the constructor makes the first undefined reference error go
away. Commenting out opEquals makes both errors go away.

--
Jul 20 2014