www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11864] New: std.variant.Variant doesn't work with CTFE

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11864

           Summary: std.variant.Variant doesn't work with CTFE
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: tcdknutson gmail.com



PST ---
e.g.

---
import std.variant : Variant;

Variant makeVariant(T)(T value)
{
    return Variant(value);
}

void main()
{
    const a = makeVariant("bar");
    pragma(msg, a);
}
---

Results in:

/opt/compilers/dmd2/include/std/variant.d(547): Error: memcpy cannot be
interpreted at compile time, because it has no available source code
/opt/compilers/dmd2/include/std/variant.d(512):        called from here:
this.opAssign(value)
/d214/f186.d(6):        called from here: (VariantN!(32LU) __ctmp1402 =
VariantN;
 , __ctmp1402).this(value)
/d214/f186.d(11):        called from here: makeVariant("bar")
/d214/f186.d(12):        while evaluating a.init
/d214/f186.d(12):        while evaluating pragma(msg, a)


Note that the error doesn't happen if pragma(msg, a) is removed. I guess the
compiler is lazily evaluating 'a'?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 03 2014
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11864


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement



 Note that the error doesn't happen if pragma(msg, a) is removed. I guess the
compiler is lazily evaluating 'a'? No, 'a' is normally just a run-time value. By putting it in a pragma(msg), you're asking the compiler to evaluate it at compile time. This fails because Variant uses memcpy. This isn't a bug. Replacing the memcpy with an array slice assignment would just cause it to fail in a different way. Variants are intrinsically a bit nasty, they're basically a union, so there's actually multiple reasons why they don't work in CTFE. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 14 2014